# HG changeset patch
# User Pantxo Diribarne <pantxo.diribarne@gmail.com>
# Date 1567671219 -7200
#      Thu Sep 05 10:13:39 2019 +0200
# Node ID 0fe9f21086cb7e12add819f325bb3ef15e791219
# Parent  682695bd0e98cea1a837cb4c9dca4e1f1b793bf2
Allow Qt graphics callbacks to work again (bug #56857)

* Object.h, Object.cc (Object::do_connections): New virtual method. Do
  connections that were previously done in qt_graphics_toolkit::create_object

* qt_graphics_toolkit.cc (qt_graphics_toolkit::create_object): Let
  Object::do_connections do the signal/slot connections.

* Figure.h, Figure.cc (Figure::do_connection): Overload Object::do_connections
  to also make connections on peer Canvas object.

* Panel.h, Panel.cc (Panel::do_connection): Overload Object::do_connections
  to also make connections on peer Canvas object.

diff -r 682695bd0e98 -r 0fe9f21086cb libgui/graphics/Canvas.cc
--- a/libgui/graphics/Canvas.cc	Sat Aug 31 15:10:03 2019 +0900
+++ b/libgui/graphics/Canvas.cc	Thu Sep 05 10:13:39 2019 +0200
@@ -1022,7 +1022,7 @@
             if (redrawFigure)
               redraw (false);
           }
-        
+
         if (! figObj.get ("windowscrollwheelfcn").isempty ())
           {
             octave_scalar_map eventData = Utils::makeScrollEventStruct (event);
diff -r 682695bd0e98 -r 0fe9f21086cb libgui/graphics/Figure.cc
--- a/libgui/graphics/Figure.cc	Sat Aug 31 15:10:03 2019 +0900
+++ b/libgui/graphics/Figure.cc	Thu Sep 05 10:13:39 2019 +0200
@@ -588,6 +588,13 @@
                                 .arg (pt(1), 0, 'g', 5));
   }
 
+  void
+  Figure::do_connections (const QObject *receiver, const QObject* /**emitter*/)
+  {
+    Object::do_connections (receiver);
+    Object::do_connections (receiver, m_container->canvas (m_handle));
+  }
+
   QWidget*
   Figure::menu (void)
   {
diff -r 682695bd0e98 -r 0fe9f21086cb libgui/graphics/Figure.h
--- a/libgui/graphics/Figure.h	Sat Aug 31 15:10:03 2019 +0900
+++ b/libgui/graphics/Figure.h	Thu Sep 05 10:13:39 2019 +0200
@@ -77,6 +77,9 @@
     QWidget * menu (void);
     void updateStatusBar (ColumnVector pt);
 
+    void do_connections (const QObject *receiver,
+                         const QObject *emitter = nullptr);
+
     bool eventNotifyBefore (QObject *watched, QEvent *event);
     void eventNotifyAfter (QObject *watched, QEvent *event);
 
diff -r 682695bd0e98 -r 0fe9f21086cb libgui/graphics/Object.cc
--- a/libgui/graphics/Object.cc	Sat Aug 31 15:10:03 2019 +0900
+++ b/libgui/graphics/Object.cc	Thu Sep 05 10:13:39 2019 +0200
@@ -215,4 +215,71 @@
     return nullptr;
   }
 
+  void
+  Object::do_connections (const QObject *receiver, const QObject *emitter)
+  {
+    if (! emitter)
+      emitter = this;
+
+    connect (emitter,
+             SIGNAL (interpreter_event (const octave::fcn_callback&)),
+             receiver,
+             SLOT (interpreter_event (const octave::fcn_callback&)));
+
+    connect (emitter,
+             SIGNAL (interpreter_event (const octave::meth_callback&)),
+             receiver,
+             SLOT (interpreter_event (const octave::meth_callback&)));
+
+    connect (emitter,
+             SIGNAL (interpreter_event (const octave::meth_callback&)),
+             receiver,
+             SLOT (interpreter_event (const octave::meth_callback&)));
+
+    connect (emitter,
+             SIGNAL (gh_callback_event (const graphics_handle&,
+                                        const std::string&)),
+             receiver,
+             SLOT (gh_callback_event (const graphics_handle&,
+                                      const std::string&)));
+
+    connect (emitter,
+             SIGNAL (gh_callback_event (const graphics_handle&,
+                                        const std::string&,
+                                        const octave_value&)),
+             receiver,
+             SLOT (gh_callback_event (const graphics_handle&,
+                                      const std::string&,
+                                      const octave_value&)));
+
+    connect (emitter,
+             SIGNAL (gh_set_event (const graphics_handle&,
+                                   const std::string&,
+                                   const octave_value&)),
+             receiver,
+             SLOT (gh_set_event (const graphics_handle&,
+                                 const std::string&,
+                                 const octave_value&)));
+
+    connect (emitter,
+             SIGNAL (gh_set_event (const graphics_handle&,
+                                   const std::string&,
+                                   const octave_value&, bool)),
+             receiver,
+             SLOT (gh_set_event (const graphics_handle&,
+                                 const std::string&,
+                                 const octave_value&, bool)));
+
+    connect (emitter,
+             SIGNAL (gh_set_event (const graphics_handle&,
+                                   const std::string&,
+                                   const octave_value&,
+                                   bool, bool)),
+             receiver,
+             SLOT (gh_set_event (const graphics_handle&,
+                                 const std::string&,
+                                 const octave_value&,
+                                 bool, bool)));
+  }
+
 }
diff -r 682695bd0e98 -r 0fe9f21086cb libgui/graphics/Object.h
--- a/libgui/graphics/Object.h	Sat Aug 31 15:10:03 2019 +0900
+++ b/libgui/graphics/Object.h	Thu Sep 05 10:13:39 2019 +0200
@@ -78,6 +78,9 @@
 
     static Object * fromQObject (QObject *obj);
 
+    virtual void do_connections (const QObject *receiver,
+                                 const QObject *emitter = nullptr);
+
   signals:
 
     void interpreter_event (const octave::fcn_callback& fcn);
diff -r 682695bd0e98 -r 0fe9f21086cb libgui/graphics/Panel.cc
--- a/libgui/graphics/Panel.cc	Sat Aug 31 15:10:03 2019 +0900
+++ b/libgui/graphics/Panel.cc	Thu Sep 05 10:13:39 2019 +0200
@@ -147,11 +147,11 @@
 
     frame->installEventFilter (this);
     m_container->installEventFilter (this);
-    
+
     graphics_object fig (go.get_ancestor ("figure"));
     if (! fig.get ("keypressfcn").isempty ())
       m_container->canvas (m_handle)->addEventMask (Canvas::KeyPress);
-    
+
     if (! fig.get ("keyreleasefcn").isempty ())
       m_container->canvas (m_handle)->addEventMask (Canvas::KeyRelease);
 
@@ -405,4 +405,11 @@
       }
   }
 
+  void
+  Panel::do_connections (const QObject *receiver, const QObject* /**emitter*/)
+  {
+    Object::do_connections (receiver);
+    Object::do_connections (receiver, m_container->canvas (m_handle));
+  }
+
 };
diff -r 682695bd0e98 -r 0fe9f21086cb libgui/graphics/Panel.h
--- a/libgui/graphics/Panel.h	Sat Aug 31 15:10:03 2019 +0900
+++ b/libgui/graphics/Panel.h	Thu Sep 05 10:13:39 2019 +0200
@@ -45,6 +45,9 @@
 
     static Panel * create (const graphics_object& go);
 
+    void do_connections (const QObject *receiver,
+                         const QObject *emitter = nullptr);
+
   protected:
     void update (int pId);
     void redraw (void);
diff -r 682695bd0e98 -r 0fe9f21086cb libgui/graphics/qt-graphics-toolkit.cc
--- a/libgui/graphics/qt-graphics-toolkit.cc	Sat Aug 31 15:10:03 2019 +0900
+++ b/libgui/graphics/qt-graphics-toolkit.cc	Thu Sep 05 10:13:39 2019 +0200
@@ -431,66 +431,7 @@
                 if (obj)
                   {
                     proxy->setObject (obj);
-
-                    connect (obj,
-                             SIGNAL (interpreter_event (const octave::fcn_callback&)),
-                             this,
-                             SLOT (interpreter_event (const octave::fcn_callback&)));
-
-                    connect (obj,
-                             SIGNAL (interpreter_event (const octave::meth_callback&)),
-                             this,
-                             SLOT (interpreter_event (const octave::meth_callback&)));
-
-                    connect (obj,
-                             SIGNAL (interpreter_event (const octave::meth_callback&)),
-                             this,
-                             SLOT (interpreter_event (const octave::meth_callback&)));
-
-                    connect (obj,
-                             SIGNAL (gh_callback_event (const graphics_handle&,
-                                                        const std::string&)),
-                             this,
-                             SLOT (gh_callback_event (const graphics_handle&,
-                                                      const std::string&)));
-
-                    connect (obj,
-                             SIGNAL (gh_callback_event (const graphics_handle&,
-                                                        const std::string&,
-                                                        const octave_value&)),
-                             this,
-                             SLOT (gh_callback_event (const graphics_handle&,
-                                                      const std::string&,
-                                                      const octave_value&)));
-
-                    connect (obj,
-                             SIGNAL (gh_set_event (const graphics_handle&,
-                                                   const std::string&,
-                                                   const octave_value&)),
-                             this,
-                             SLOT (gh_set_event (const graphics_handle&,
-                                                 const std::string&,
-                                                 const octave_value&)));
-
-                    connect (obj,
-                             SIGNAL (gh_set_event (const graphics_handle&,
-                                                   const std::string&,
-                                                   const octave_value&, bool)),
-                             this,
-                             SLOT (gh_set_event (const graphics_handle&,
-                                                 const std::string&,
-                                                 const octave_value&, bool)));
-
-                    connect (obj,
-                             SIGNAL (gh_set_event (const graphics_handle&,
-                                                   const std::string&,
-                                                   const octave_value&,
-                                                   bool, bool)),
-                             this,
-                             SLOT (gh_set_event (const graphics_handle&,
-                                                 const std::string&,
-                                                 const octave_value&,
-                                                 bool, bool)));
+                    obj->do_connections (this);
                   }
               }
             else
