changeset 27316:22265a75be74

eliminate static instance of Qt graphics ObjectFactory class * Backend.h, Backend.cc (Backend::m_factory): New member variable. Backend object now owns the ObjectFactory. (Backend::Backend): Create ObjectFactory here. (Backend::~Backend): Delete it. * ObjectFactory.h, ObjectFactory.cc (ObjectFactory::instance): Delete. (ObjectFactory::ObjectFactory): Now public.
author John W. Eaton <jwe@octave.org>
date Tue, 30 Jul 2019 15:00:54 -0500
parents 86c5dd1283b6
children 718116e9c7d3
files libgui/graphics/Backend.cc libgui/graphics/Backend.h libgui/graphics/ObjectFactory.cc libgui/graphics/ObjectFactory.h
diffstat 4 files changed, 15 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/graphics/Backend.cc	Mon Aug 05 08:51:40 2019 -0700
+++ b/libgui/graphics/Backend.cc	Tue Jul 30 15:00:54 2019 -0500
@@ -76,17 +76,21 @@
   }
 
   Backend::Backend (octave::interpreter& interp)
-    : QObject (), base_graphics_toolkit ("qt"), m_interpreter (interp)
+    : QObject (), base_graphics_toolkit ("qt"), m_interpreter (interp),
+      m_factory (new ObjectFactory ())
   {
-    ObjectFactory *factory = ObjectFactory::instance ();
+    if (QThread::currentThread () != QApplication::instance ()->thread ())
+      m_factory->moveToThread (QApplication::instance ()->thread ());
 
     connect (this, SIGNAL (createObject (Backend *, double)),
-             factory, SLOT (createObject (Backend *, double)),
+             m_factory, SLOT (createObject (Backend *, double)),
              Qt::BlockingQueuedConnection);
   }
 
   Backend::~Backend (void)
-  { }
+  {
+    delete m_factory;
+  }
 
   bool
   Backend::initialize (const graphics_object& go)
--- a/libgui/graphics/Backend.h	Mon Aug 05 08:51:40 2019 -0700
+++ b/libgui/graphics/Backend.h	Tue Jul 30 15:00:54 2019 -0500
@@ -35,8 +35,8 @@
 
 namespace QtHandles
 {
-
   class Object;
+  class ObjectFactory;
   class ObjectProxy;
 
   class Backend :
@@ -46,6 +46,7 @@
     Q_OBJECT
 
   public:
+
     Backend (octave::interpreter& interp);
 
     ~Backend (void);
@@ -86,6 +87,8 @@
   private:
 
     octave::interpreter& m_interpreter;
+
+    ObjectFactory *m_factory;
   };
 
 }
--- a/libgui/graphics/ObjectFactory.cc	Mon Aug 05 08:51:40 2019 -0700
+++ b/libgui/graphics/ObjectFactory.cc	Tue Jul 30 15:00:54 2019 -0500
@@ -56,23 +56,6 @@
 
 namespace QtHandles
 {
-
-  ObjectFactory*
-  ObjectFactory::instance (void)
-  {
-    static ObjectFactory s_instance;
-    static bool s_instanceCreated = false;
-
-    if (! s_instanceCreated)
-      {
-        if (QThread::currentThread () != QApplication::instance ()->thread ())
-          s_instance.moveToThread (QApplication::instance ()->thread ());
-        s_instanceCreated = true;
-      }
-
-    return &s_instance;
-  }
-
   void
   ObjectFactory::createObject (Backend *backend, double handle)
   {
--- a/libgui/graphics/ObjectFactory.h	Mon Aug 05 08:51:40 2019 -0700
+++ b/libgui/graphics/ObjectFactory.h	Tue Jul 30 15:00:54 2019 -0500
@@ -37,15 +37,12 @@
     Q_OBJECT
 
   public:
-    static ObjectFactory * instance (void);
+
+    ObjectFactory (void) : QObject () { }
 
   public slots:
+
     void createObject (Backend *, double handle);
-
-  private:
-    ObjectFactory (void)
-      : QObject ()
-    { }
   };
 
 };