# HG changeset patch # User John W. Eaton # Date 1423515962 18000 # Node ID 7335cc071ab034a6a2b979dd73795b91831cba20 # Parent 2b93834e5ede3a37c55023382f1b998722902886 make save and saveas menu items work in Qt figure window See also bug #44177. * Figure.h, Figure.cc (Figure::fileName, Figure::setFileName, Figure::save_figure_callback): New functions. (Figure::createFigureToolBarAndMenuBar): Enable Save and "Save As" items and connect them to new fileSaveFigure and fileSaveFigureAS functions. diff -r 2b93834e5ede -r 7335cc071ab0 libgui/graphics/Figure.cc --- a/libgui/graphics/Figure.cc Mon Feb 09 21:36:01 2015 +0100 +++ b/libgui/graphics/Figure.cc Mon Feb 09 16:06:02 2015 -0500 @@ -29,6 +29,8 @@ #include #include #include +#include +#include #include #include #include @@ -45,6 +47,10 @@ #include "MouseModeActionGroup.h" #include "QtHandlesUtils.h" +#include "octave-qt-link.h" + +#include "builtin-defun-decls.h" + namespace QtHandles { @@ -210,6 +216,26 @@ return NoMode; } +QString Figure::fileName (void) +{ + gh_manager::auto_lock lock; + + const figure::properties& fp = properties
(); + + std::string name = fp.get_filename (); + + return QString::fromStdString (name); +} + +void Figure::setFileName (const QString& name) +{ + gh_manager::auto_lock lock; + + figure::properties& fp = properties
(); + + fp.set_filename (name.toStdString ()); +} + MouseMode Figure::mouseMode (void) { gh_manager::auto_lock lock; @@ -250,8 +276,8 @@ fileMenu->addAction (tr ("&New Figure"), this, SLOT (fileNewFigure (void))); fileMenu->addAction (tr ("&Open..."))->setEnabled (false); fileMenu->addSeparator (); - fileMenu->addAction (tr ("&Save"))->setEnabled (false); - fileMenu->addAction (tr ("Save &As"))->setEnabled (false); + fileMenu->addAction (tr ("&Save"), this, SLOT (fileSaveFigure (bool))); + fileMenu->addAction (tr ("Save &As"), this, SLOT (fileSaveFigureAs (void))); fileMenu->addSeparator (); fileMenu->addAction (tr ("&Close Figure"), this, SLOT (fileCloseFigure (void)), Qt::CTRL|Qt::Key_W); @@ -699,6 +725,48 @@ { } +void Figure::fileSaveFigure (bool prompt) +{ + QString file = fileName (); + + if (file.isEmpty ()) + { + prompt = true; + + file = "untitled.eps"; + } + + if (prompt || file.isEmpty ()) + { + QFileInfo finfo (file); + + file = QFileDialog::getSaveFileName (qWidget (), + tr ("Save Figure As"), + finfo.absoluteFilePath (), 0, 0, + QFileDialog::DontUseNativeDialog); + } + + if (! file.isEmpty ()) + { + QFileInfo finfo (file); + + setFileName (finfo.absoluteFilePath ()); + + octave_link::post_event (this, &Figure::save_figure_callback, + file.toStdString ()); + } +} + +void Figure::save_figure_callback (const std::string& file) +{ + Ffeval (ovl ("print", file)); +} + +void Figure::fileSaveFigureAs (void) +{ + fileSaveFigure (true); +} + void Figure::fileCloseFigure (void) { qWidget ()->close (); diff -r 2b93834e5ede -r 7335cc071ab0 libgui/graphics/Figure.h --- a/libgui/graphics/Figure.h Mon Feb 09 21:36:01 2015 +0100 +++ b/libgui/graphics/Figure.h Mon Feb 09 16:06:02 2015 -0500 @@ -70,6 +70,9 @@ static Figure* create (const graphics_object& go); + QString fileName (void); + void setFileName (const QString& name); + MouseMode mouseMode (void); Container* innerContainer (void); @@ -104,9 +107,13 @@ static void updateBoundingBoxHelper (void*); + void save_figure_callback (const std::string& file); + private slots: void setMouseMode (MouseMode mode); void fileNewFigure (void); + void fileSaveFigure (bool prompt = false); + void fileSaveFigureAs (void); void fileCloseFigure (void); void editCopy (void); void editCut (void); diff -r 2b93834e5ede -r 7335cc071ab0 libgui/graphics/module.mk --- a/libgui/graphics/module.mk Mon Feb 09 21:36:01 2015 +0100 +++ b/libgui/graphics/module.mk Mon Feb 09 16:06:02 2015 -0500 @@ -116,6 +116,7 @@ @OCTGUI_DLL_DEFS@ \ @QT_CPPFLAGS@ \ -Igraphics -I$(srcdir)/graphics \ + -Isrc -I$(srcdir)/src \ -I$(top_srcdir)/liboctave/cruft/misc \ -I$(top_srcdir)/liboctave/array \ -I$(top_builddir)/liboctave/numeric -I$(top_srcdir)/liboctave/numeric \