changeset 19715:35bca657d74d

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.
author John W. Eaton <jwe@octave.org>
date Sun, 08 Feb 2015 16:25:06 -0500
parents 890ff06d84ce
children c2478360291f
files libgui/graphics/Backend.cc libgui/graphics/Backend.h libgui/graphics/Canvas.cc libgui/graphics/Canvas.h libgui/graphics/Figure.cc libgui/graphics/Figure.h libgui/graphics/Object.cc libgui/graphics/Object.h libgui/graphics/ObjectProxy.cc libgui/graphics/ObjectProxy.h
diffstat 10 files changed, 76 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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);
--- 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);
--- 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)
 {
--- 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; }
--- 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);
--- 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);
--- 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 <config.h>
 #endif
 
+#include <QString>
 #include <QVariant>
 
 #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)
 {
 }
--- 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);
 
--- 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 <config.h>
 #endif
 
+#include <QString>
+
 #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);
+}
+
 };
--- 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 <QObject>
 
+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);