changeset 27694:b3401292e101

store Qt graphics toolkit object in interpreter_qobject * graphics-init.h, graphics-init.cc: Delete. * libgui/src/module.mk: Update. * interpreter-qobject.h, interpreter-qobject.cc (interpreter::m_graphics_toolkit): New member variable. (interpreter::graphics_init): New member function, adapted from global graphics_init function. (interpreter::execute): Update graphics_init call. (interpreter_qobject::~interpreter_qobject): Delete m_graphics_toolkit.
author John W. Eaton <jwe@octave.org>
date Thu, 14 Nov 2019 21:35:14 -0500
parents de4bfeda8d9f
children cdb681adc85a
files libgui/src/graphics-init.cc libgui/src/graphics-init.h libgui/src/interpreter-qobject.cc libgui/src/interpreter-qobject.h libgui/src/module.mk
diffstat 5 files changed, 53 insertions(+), 121 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/src/graphics-init.cc	Thu Nov 14 13:15:31 2019 -0800
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,76 +0,0 @@
-/*
-
-Copyright (C) 2019 John W. Eaton
-
-This file is part of Octave.
-
-Octave is free software: you can redistribute it and/or modify it
-under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-Octave is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with Octave; see the file COPYING.  If not, see
-<https://www.gnu.org/licenses/>.
-
-*/
-
-#if defined (HAVE_CONFIG_H)
-#  include "config.h"
-#endif
-
-#include <QApplication>
-#include <QMetaType>
-#include <QThread>
-
-#include "graphics-init.h"
-#include "octave-qobject.h"
-#include "qt-graphics-toolkit.h"
-#include "QtHandlesUtils.h"
-
-#include "graphics.h"
-#include "gtk-manager.h"
-#include "interpreter.h"
-
-namespace octave
-{
-  void graphics_init (interpreter& interp, base_qobject& oct_qobj)
-  {
-#if defined (HAVE_QT_GRAPHICS)
-
-    gh_manager& gh_mgr = interp.get_gh_manager ();
-
-    autolock guard (gh_mgr.graphics_lock ());
-
-    qRegisterMetaType<graphics_object> ("graphics_object");
-
-    gh_mgr.enable_event_processing (true);
-
-    QtHandles::qt_graphics_toolkit *qt_gtk
-      = new QtHandles::qt_graphics_toolkit (interp, oct_qobj);
-
-    if (QThread::currentThread ()
-        != QApplication::instance ()->thread ())
-      qt_gtk->moveToThread (QApplication::instance ()->thread ());
-
-    graphics_toolkit tk (qt_gtk);
-
-    octave::gtk_manager& gtk_mgr = interp.get_gtk_manager ();
-
-    gtk_mgr.register_toolkit ("qt");
-
-    gtk_mgr.load_toolkit (tk);
-
-#else
-
-    octave_unused_parameter (interp);
-    octave_unused_parameter (oct_qobj);
-
-#endif
-  }
-}
--- a/libgui/src/graphics-init.h	Thu Nov 14 13:15:31 2019 -0800
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,39 +0,0 @@
-/*
-
-Copyright (C) 2019 John W. Eaton
-
-This file is part of Octave.
-
-Octave is free software: you can redistribute it and/or modify it
-under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-Octave is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with Octave; see the file COPYING.  If not, see
-<https://www.gnu.org/licenses/>.
-
-*/
-
-#if ! defined (octave_graphics_init_h)
-#define octave_graphics_init_h 1
-
-#include <QObject>
-
-#include "qt-interpreter-events.h"
-
-namespace octave
-{
-  class interpreter;
-
-  class base_qobject;
-
-  extern void graphics_init (interpreter& interp, base_qobject& oct_qobj);
-}
-
-#endif
--- a/libgui/src/interpreter-qobject.cc	Thu Nov 14 13:15:31 2019 -0800
+++ b/libgui/src/interpreter-qobject.cc	Thu Nov 14 21:35:14 2019 -0500
@@ -25,19 +25,27 @@
 #  include "config.h"
 #endif
 
+#include <QApplication>
+#include <QMetaType>
+#include <QThread>
+
+#include "QtHandlesUtils.h"
 #include "interpreter-qobject.h"
 #include "octave-qobject.h"
 #include "qt-application.h"
+#include "qt-graphics-toolkit.h"
 #include "qt-interpreter-events.h"
 
-#include "graphics-init.h"
+#include "graphics.h"
+#include "gtk-manager.h"
 #include "input.h"
 #include "interpreter.h"
 
 namespace octave
 {
   interpreter_qobject::interpreter_qobject (base_qobject& oct_qobj)
-    : QObject (), m_octave_qobj (oct_qobj), m_interpreter (nullptr)
+    : QObject (), m_octave_qobj (oct_qobj), m_interpreter (nullptr),
+      m_graphics_toolkit (nullptr)
   { }
 
   void interpreter_qobject::execute (void)
@@ -78,7 +86,7 @@
 
             emit octave_ready_signal ();
 
-            graphics_init (interp, m_octave_qobj);
+            graphics_init ();
 
             // Start executing commands in the command window.
 
@@ -102,6 +110,41 @@
     emit octave_finished_signal (exit_status);
   }
 
+  interpreter_qobject::~interpreter_qobject (void)
+  {
+    delete m_graphics_toolkit;
+  }
+
+  void interpreter_qobject::graphics_init (void)
+  {
+#if defined (HAVE_QT_GRAPHICS)
+
+    gh_manager& gh_mgr = m_interpreter->get_gh_manager ();
+
+    autolock guard (gh_mgr.graphics_lock ());
+
+    qRegisterMetaType<graphics_object> ("graphics_object");
+
+    gh_mgr.enable_event_processing (true);
+
+    QtHandles::qt_graphics_toolkit *qt_gtk
+      = new QtHandles::qt_graphics_toolkit (*m_interpreter, m_octave_qobj);
+
+    if (QThread::currentThread ()
+        != QApplication::instance ()->thread ())
+      qt_gtk->moveToThread (QApplication::instance ()->thread ());
+
+    m_graphics_toolkit = new graphics_toolkit (qt_gtk);
+
+    octave::gtk_manager& gtk_mgr = m_interpreter->get_gtk_manager ();
+
+    gtk_mgr.register_toolkit ("qt");
+
+    gtk_mgr.load_toolkit (*m_graphics_toolkit);
+
+#endif
+  }
+
   void interpreter_qobject::interpreter_event (const fcn_callback& fcn)
   {
     if (! m_interpreter)
--- a/libgui/src/interpreter-qobject.h	Thu Nov 14 13:15:31 2019 -0800
+++ b/libgui/src/interpreter-qobject.h	Thu Nov 14 21:35:14 2019 -0500
@@ -28,6 +28,8 @@
 
 #include "qt-interpreter-events.h"
 
+class graphics_toolkit;
+
 namespace octave
 {
   class interpreter;
@@ -42,7 +44,9 @@
 
     interpreter_qobject (base_qobject& oct_qobj);
 
-    ~interpreter_qobject (void) = default;
+    ~interpreter_qobject (void);
+
+    void graphics_init (void);
 
     qt_interpreter_events * qt_link (void);
 
@@ -85,6 +89,8 @@
     base_qobject& m_octave_qobj;
 
     interpreter *m_interpreter;
+
+    graphics_toolkit *m_graphics_toolkit;
   };
 }
 
--- a/libgui/src/module.mk	Thu Nov 14 13:15:31 2019 -0800
+++ b/libgui/src/module.mk	Thu Nov 14 21:35:14 2019 -0500
@@ -204,7 +204,6 @@
   %reldir%/gui-settings.h \
   %reldir%/external-editor-interface.h \
   %reldir%/files-dock-widget.h \
-  %reldir%/graphics-init.h \
   %reldir%/history-dock-widget.h \
   %reldir%/interpreter-qobject.h \
   %reldir%/m-editor/file-editor-interface.h \
@@ -243,7 +242,6 @@
   %reldir%/dw-main-window.cc \
   %reldir%/external-editor-interface.cc \
   %reldir%/files-dock-widget.cc \
-  %reldir%/graphics-init.cc \
   %reldir%/gui-settings.cc \
   %reldir%/history-dock-widget.cc \
   %reldir%/interpreter-qobject.cc \