浏览代码

Merge branch 'pimplify-ctkAbstractPythonManager'

* pimplify-ctkAbstractPythonManager:
  "Pimpl-ify" ctkAbstractPythonManager - Implementation moved to cpp file
Jean-Christophe Fillion-Robin 13 年之前
父节点
当前提交
424de34e02

+ 41 - 7
Libs/Scripting/Python/Core/ctkAbstractPythonManager.cpp

@@ -41,12 +41,43 @@
 #endif
 
 //-----------------------------------------------------------------------------
-ctkAbstractPythonManager::ctkAbstractPythonManager(QObject* _parent) : Superclass(_parent)
+class ctkAbstractPythonManagerPrivate
+{
+  Q_DECLARE_PUBLIC(ctkAbstractPythonManager);
+protected:
+  ctkAbstractPythonManager* q_ptr;
+public:
+  ctkAbstractPythonManagerPrivate(ctkAbstractPythonManager& object);
+  virtual ~ctkAbstractPythonManagerPrivate();
+
+  void (*InitFunction)();
+};
+
+//-----------------------------------------------------------------------------
+// ctkAbstractPythonManagerPrivate methods
+
+//-----------------------------------------------------------------------------
+ctkAbstractPythonManagerPrivate::ctkAbstractPythonManagerPrivate(ctkAbstractPythonManager &object) :
+  q_ptr(&object)
 {
   this->InitFunction = 0;
 }
 
 //-----------------------------------------------------------------------------
+ctkAbstractPythonManagerPrivate::~ctkAbstractPythonManagerPrivate()
+{
+}
+
+//-----------------------------------------------------------------------------
+// ctkAbstractPythonManager methods
+
+//-----------------------------------------------------------------------------
+ctkAbstractPythonManager::ctkAbstractPythonManager(QObject* _parent) : Superclass(_parent),
+  d_ptr(new ctkAbstractPythonManagerPrivate(*this))
+{
+}
+
+//-----------------------------------------------------------------------------
 ctkAbstractPythonManager::~ctkAbstractPythonManager()
 {
   if (Py_IsInitialized())
@@ -74,6 +105,8 @@ PythonQtObjectPtr ctkAbstractPythonManager::mainContext()
 //-----------------------------------------------------------------------------
 void ctkAbstractPythonManager::initPythonQt()
 {
+  Q_D(ctkAbstractPythonManager);
+
   PythonQt::init(PythonQt::IgnoreSiteModule | PythonQt::RedirectStdOut);
 
   // Python maps SIGINT (control-c) to its own handler.  We will remap it
@@ -88,14 +121,14 @@ void ctkAbstractPythonManager::initPythonQt()
                 SLOT(printStdout(QString)));
   this->connect(PythonQt::self(), SIGNAL(pythonStdErr(QString)),
                 SLOT(printStderr(QString)));
-  
+
   PythonQt_init_QtBindings();
-  
+
   QStringList initCode;
 
   // Update 'sys.path'
   initCode << "import sys";
-  foreach (QString path, this->pythonPaths())
+  foreach (const QString& path, this->pythonPaths())
     {
     initCode << QString("sys.path.append('%1')").arg(QDir::fromNativeSeparators(path));
     }
@@ -105,9 +138,9 @@ void ctkAbstractPythonManager::initPythonQt()
   _mainContext.evalScript(initCode.join("\n"));
 
   this->preInitialization();
-  if (this->InitFunction)
+  if (d->InitFunction)
     {
-    (*this->InitFunction)();
+    (*d->InitFunction)();
     }
   emit this->pythonPreInitialized();
 
@@ -196,7 +229,8 @@ void ctkAbstractPythonManager::executeFile(const QString& filename)
 //-----------------------------------------------------------------------------
 void ctkAbstractPythonManager::setInitializationFunction(void (*initFunction)())
 {
-  this->InitFunction = initFunction;
+  Q_D(ctkAbstractPythonManager);
+  d->InitFunction = initFunction;
 }
 
 //----------------------------------------------------------------------------

+ 7 - 2
Libs/Scripting/Python/Core/ctkAbstractPythonManager.h

@@ -29,6 +29,7 @@
 // CTK includes
 #include "ctkScriptingPythonCoreExport.h"
 
+class ctkAbstractPythonManagerPrivate;
 class PythonQtObjectPtr;
 
 /// \ingroup Scripting_Python_Core
@@ -39,7 +40,7 @@ class CTK_SCRIPTING_PYTHON_CORE_EXPORT ctkAbstractPythonManager : public QObject
 public:
   typedef QObject Superclass;
   ctkAbstractPythonManager(QObject* _parent=NULL);
-  ~ctkAbstractPythonManager();
+  virtual ~ctkAbstractPythonManager();
 
   PythonQtObjectPtr mainContext();
   void addObjectToPythonMain(const QString& name, QObject* obj);
@@ -117,8 +118,12 @@ protected:
   /// Overload this function to execute script at initialization time
   virtual void            executeInitializationScripts();
 
+protected:
+  QScopedPointer<ctkAbstractPythonManagerPrivate> d_ptr;
+
 private:
-  void (*InitFunction)();
+  Q_DECLARE_PRIVATE(ctkAbstractPythonManager);
+  Q_DISABLE_COPY(ctkAbstractPythonManager);
 
 };
 #endif