Sfoglia il codice sorgente

Define ctkErrorLogLevel::logLevelAsString as static for easier re-use

Explicitly add associated decorator. See code comment for explanation.
Jean-Christophe Fillion-Robin 11 anni fa
parent
commit
637da4b68e

+ 13 - 0
Libs/Core/ctkCorePythonQtDecorators.h

@@ -25,6 +25,7 @@
 #include <PythonQt.h>
 
 // CTK includes
+#include <ctkErrorLogModel.h>
 #include <ctkWorkflowStep.h>
 #include <ctkWorkflowTransitions.h>
 
@@ -160,11 +161,23 @@ public Q_SLOTS:
     {
     delete transition;
     }
+
+  // ctkErrorLogLevel
+
+  QString static_ctkErrorLogLevel_logLevelAsString(ctkErrorLogLevel::LogLevel logLevel)
+    {
+    return ctkErrorLogLevel::logLevelAsString(logLevel);
+    }
 };
 
 //-----------------------------------------------------------------------------
 void initCTKCorePythonQtDecorators()
 {
+  // HACK: Since the CMake based light wrapping only consider class name matching the
+  //       filename where the class is defined, let's explicitly register ctkErrorLogLevel
+  //       so that the log level QFlags are exposed to python.
+  PythonQt::self()->registerClass(&ctkErrorLogLevel::staticMetaObject, "CTKCore");
+
   PythonQt::self()->addDecorators(new ctkCorePythonQtDecorators);
 }
 

+ 3 - 3
Libs/Core/ctkErrorLogModel.cpp

@@ -55,13 +55,13 @@ ctkErrorLogLevel::ctkErrorLogLevel()
 // --------------------------------------------------------------------------
 QString ctkErrorLogLevel::operator()(ctkErrorLogLevel::LogLevel logLevel)
 {
-  return this->logLevelAsString(logLevel);
+  return ctkErrorLogLevel::logLevelAsString(logLevel);
 }
 
 // --------------------------------------------------------------------------
-QString ctkErrorLogLevel::logLevelAsString(ctkErrorLogLevel::LogLevel logLevel)const
+QString ctkErrorLogLevel::logLevelAsString(ctkErrorLogLevel::LogLevel logLevel)
 {
-  QMetaEnum logLevelEnum = this->metaObject()->enumerator(0);
+  QMetaEnum logLevelEnum = ctkErrorLogLevel::staticMetaObject.enumerator(0);
   Q_ASSERT(QString("LogLevel").compare(logLevelEnum.name()) == 0);
   return QLatin1String(logLevelEnum.valueToKey(logLevel));
 }

+ 1 - 1
Libs/Core/ctkErrorLogModel.h

@@ -54,7 +54,7 @@ public:
 
   QString operator ()(LogLevel logLevel);
 
-  QString logLevelAsString(ctkErrorLogLevel::LogLevel logLevel)const;
+  static QString logLevelAsString(ctkErrorLogLevel::LogLevel logLevel);
 };
 Q_DECLARE_OPERATORS_FOR_FLAGS(ctkErrorLogLevel::LogLevels)