# HG changeset patch # User John W. Eaton # Date 1423430706 18000 # Node ID 35bca657d74df7892f5593b2bda6f3d3dbb07349 # Parent 890ff06d84ce852f97effe49b06e4e00cbc8beaf printing for Qt plot widget (bug #42537) * Backend.h, Backend.cc (Backend::print_figure): New function. * Canvas.h, Canvas.cc (Canvas::print): New function. * Figure.h, Figure.cc (Figure:print): New function. * Object.h, Object.cc (Object::slotPrint, Object::print): New functions. * ObjectProxy.h, ObjectProxy.cc (ObjectProxy::print): New function. (ObjectProxy::sendPrint): New signal. (ObjectProxy::init): Connect sendPrint signal to slotPrint slot of current object. diff -r 890ff06d84ce -r 35bca657d74d libgui/graphics/Backend.cc --- a/libgui/graphics/Backend.cc Sun Feb 08 12:10:05 2015 -0800 +++ b/libgui/graphics/Backend.cc Sun Feb 08 16:25:06 2015 -0500 @@ -172,6 +172,21 @@ } } +void Backend::print_figure (const graphics_object& go, + const std::string& term, + const std::string& file_cmd, bool /*mono*/, + const std::string& /*debug_file*/) const +{ + if (go.get_properties ().is_visible ()) + { + ObjectProxy* proxy = toolkitObjectProxy (go); + + if (proxy) + proxy->print (QString::fromStdString (file_cmd), + QString::fromStdString (term)); + } +} + Object* Backend::toolkitObject (const graphics_object& go) { ObjectProxy* proxy = toolkitObjectProxy (go); diff -r 890ff06d84ce -r 35bca657d74d libgui/graphics/Backend.h --- a/libgui/graphics/Backend.h Sun Feb 08 12:10:05 2015 -0800 +++ b/libgui/graphics/Backend.h Sun Feb 08 16:25:06 2015 -0500 @@ -54,6 +54,11 @@ void finalize (const graphics_object& obj); + void print_figure (const graphics_object& go, + const std::string& term, + const std::string& file_cmd, bool /*mono*/, + const std::string& /*debug_file*/) const; + static Object* toolkitObject (const graphics_object& go); static ObjectProxy* toolkitObjectProxy (const graphics_object& go); diff -r 890ff06d84ce -r 35bca657d74d libgui/graphics/Canvas.cc --- a/libgui/graphics/Canvas.cc Sun Feb 08 12:10:05 2015 -0800 +++ b/libgui/graphics/Canvas.cc Sun Feb 08 16:25:06 2015 -0500 @@ -38,6 +38,8 @@ #include "GLCanvas.h" #include "QtHandlesUtils.h" +#include "gl2ps-renderer.h" + namespace QtHandles { @@ -81,6 +83,18 @@ } } +void Canvas::print (const QString& file_cmd, const QString& term) +{ + graphics_object obj = gh_manager::get_object (m_handle); + + if (obj.valid_object ()) + { + graphics_object figObj (obj.get_ancestor ("figure")); + + gl2ps_print (figObj, file_cmd.toStdString (), term.toStdString ()); + } +} + void Canvas::updateCurrentPoint(const graphics_object& fig, const graphics_object& obj, QMouseEvent* event) { diff -r 890ff06d84ce -r 35bca657d74d libgui/graphics/Canvas.h --- a/libgui/graphics/Canvas.h Sun Feb 08 12:10:05 2015 -0800 +++ b/libgui/graphics/Canvas.h Sun Feb 08 16:25:06 2015 -0500 @@ -52,6 +52,8 @@ void redraw (bool sync = false); void blockRedraw (bool block = true); + void print (const QString& file_cmd, const QString& term); + void addEventMask (int m) { m_eventMask |= m; } void clearEventMask (int m) { m_eventMask &= (~m); } void setEventMask (int m) { m_eventMask = m; } diff -r 890ff06d84ce -r 35bca657d74d libgui/graphics/Figure.cc --- a/libgui/graphics/Figure.cc Sun Feb 08 12:10:05 2015 -0800 +++ b/libgui/graphics/Figure.cc Sun Feb 08 16:25:06 2015 -0500 @@ -313,6 +313,14 @@ updateFigureToolBarAndMenuBar (); } +void Figure::print (const QString& file_cmd, const QString& term) +{ + Canvas* canvas = m_container->canvas (m_handle); + + if (canvas) + canvas->print (file_cmd, term); +} + void Figure::beingDeleted (void) { Canvas* canvas = m_container->canvas (m_handle.value (), false); diff -r 890ff06d84ce -r 35bca657d74d libgui/graphics/Figure.h --- a/libgui/graphics/Figure.h Sun Feb 08 12:10:05 2015 -0800 +++ b/libgui/graphics/Figure.h Sun Feb 08 16:25:06 2015 -0500 @@ -88,6 +88,7 @@ protected: void redraw (void); + void print (const QString& file_cmd, const QString& term); void update (int pId); void updateBoundingBox (bool internal = false, int flags = 0); void beingDeleted (void); diff -r 890ff06d84ce -r 35bca657d74d libgui/graphics/Object.cc --- a/libgui/graphics/Object.cc Sun Feb 08 12:10:05 2015 -0800 +++ b/libgui/graphics/Object.cc Sun Feb 08 16:25:06 2015 -0500 @@ -24,6 +24,7 @@ #include #endif +#include #include #include "Backend.h" @@ -113,6 +114,14 @@ redraw (); } +void Object::slotPrint (const QString& file_cmd, const QString& term) +{ + gh_manager::auto_lock lock; + + if (object ().valid_object ()) + print (file_cmd, term); +} + void Object::update (int /* pId */) { } @@ -131,6 +140,10 @@ { } +void Object::print (const QString& file_cmd, const QString& term) +{ +} + void Object::beingDeleted (void) { } diff -r 890ff06d84ce -r 35bca657d74d libgui/graphics/Object.h --- a/libgui/graphics/Object.h Sun Feb 08 12:10:05 2015 -0800 +++ b/libgui/graphics/Object.h Sun Feb 08 16:25:06 2015 -0500 @@ -28,6 +28,7 @@ #include "graphics.h" class QObject; +class QString; class QWidget; namespace QtHandles @@ -80,6 +81,7 @@ void slotUpdate (int pId); void slotFinalize (void); void slotRedraw (void); + void slotPrint (const QString& file_cmd, const QString& term); void objectDestroyed (QObject *obj = 0); @@ -90,6 +92,7 @@ virtual void update (int pId); virtual void finalize (void); virtual void redraw (void); + virtual void print (const QString& file_cmd, const QString& term); virtual void beingDeleted (void); diff -r 890ff06d84ce -r 35bca657d74d libgui/graphics/ObjectProxy.cc --- a/libgui/graphics/ObjectProxy.cc Sun Feb 08 12:10:05 2015 -0800 +++ b/libgui/graphics/ObjectProxy.cc Sun Feb 08 16:25:06 2015 -0500 @@ -24,6 +24,8 @@ #include #endif +#include + #include "oct-mutex.h" #include "Object.h" @@ -50,6 +52,8 @@ m_object, SLOT (slotFinalize (void))); disconnect (this, SIGNAL (sendRedraw (void)), m_object, SLOT (slotRedraw (void))); + disconnect (this, SIGNAL (sendPrint (const QString&, const QString&)), + m_object, SLOT (slotPrint (const QString&, const QString&))); } m_object = obj; @@ -62,6 +66,8 @@ m_object, SLOT (slotFinalize (void))); connect (this, SIGNAL (sendRedraw (void)), m_object, SLOT (slotRedraw (void))); + connect (this, SIGNAL (sendPrint (const QString&, const QString&)), + m_object, SLOT (slotPrint (const QString&, const QString&))); } } } @@ -91,4 +97,9 @@ emit sendRedraw (); } + void ObjectProxy::print (const QString& file_cmd, const QString& term) +{ + emit sendPrint (file_cmd, term); +} + }; diff -r 890ff06d84ce -r 35bca657d74d libgui/graphics/ObjectProxy.h --- a/libgui/graphics/ObjectProxy.h Sun Feb 08 12:10:05 2015 -0800 +++ b/libgui/graphics/ObjectProxy.h Sun Feb 08 16:25:06 2015 -0500 @@ -25,6 +25,8 @@ #include +class QString; + namespace QtHandles { @@ -40,6 +42,7 @@ void update (int pId); void finalize (void); void redraw (void); + void print (const QString& file_cmd, const QString& term); Object* object (void) { return m_object; } void setObject (Object* obj); @@ -48,6 +51,7 @@ void sendUpdate (int pId); void sendFinalize (void); void sendRedraw (void); + void sendPrint (const QString& file_cmd, const QString& term); private: void init (Object* obj);