changeset 27376:1952e110d346

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.
author Pantxo Diribarne <pantxo.diribarne@gmail.com>
date Thu, 05 Sep 2019 10:13:39 +0200
parents 2fb37768085d
children 5ca84fb30205
files libgui/graphics/Canvas.cc libgui/graphics/Figure.cc libgui/graphics/Figure.h libgui/graphics/Object.cc libgui/graphics/Object.h libgui/graphics/Panel.cc libgui/graphics/Panel.h libgui/graphics/qt-graphics-toolkit.cc
diffstat 8 files changed, 94 insertions(+), 63 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/graphics/Canvas.cc	Thu Sep 05 17:42:07 2019 -0400
+++ 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);
--- a/libgui/graphics/Figure.cc	Thu Sep 05 17:42:07 2019 -0400
+++ 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)
   {
--- a/libgui/graphics/Figure.h	Thu Sep 05 17:42:07 2019 -0400
+++ 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);
 
--- a/libgui/graphics/Object.cc	Thu Sep 05 17:42:07 2019 -0400
+++ 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)));
+  }
+
 }
--- a/libgui/graphics/Object.h	Thu Sep 05 17:42:07 2019 -0400
+++ 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);
--- a/libgui/graphics/Panel.cc	Thu Sep 05 17:42:07 2019 -0400
+++ 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));
+  }
+
 };
--- a/libgui/graphics/Panel.h	Thu Sep 05 17:42:07 2019 -0400
+++ 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);
--- a/libgui/graphics/qt-graphics-toolkit.cc	Thu Sep 05 17:42:07 2019 -0400
+++ 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