Pārlūkot izejas kodu

Merge branch 'ctkCommandLineParser-qproperty'

* ctkCommandLineParser-qproperty:
  ctkCommandLineParser - Expose property to python using Q_PROPERTY and Q_INVOKABLE
Jean-Christophe Fillion-Robin 14 gadi atpakaļ
vecāks
revīzija
d16b45a7ff

+ 2 - 1
Libs/Core/CMakeLists.txt

@@ -61,6 +61,7 @@ ENDIF()
 
 # Headers that should run through moc
 SET(KIT_MOC_SRCS
+  ctkCommandLineParser.h
   ctkLogger.h 
   ctkHistogram.h
   ctkModelTester.h
@@ -68,7 +69,7 @@ SET(KIT_MOC_SRCS
   ctkTransferFunctionRepresentation.h
   ctkWorkflow.h
   ctkWorkflowStep_p.h
- ctkWorkflowTransitions.h
+  ctkWorkflowTransitions.h
   )
 
 # UI files

+ 8 - 1
Libs/Core/ctkCommandLineParser.cpp

@@ -269,7 +269,14 @@ CommandLineParserArgumentDescription*
 // ctkCommandLineParser methods
 
 // --------------------------------------------------------------------------
-ctkCommandLineParser::ctkCommandLineParser(QSettings* settings)
+ctkCommandLineParser::ctkCommandLineParser(QObject* newParent) : Superclass(newParent)
+{
+  this->Internal = new ctkInternal(0);
+}
+
+// --------------------------------------------------------------------------
+ctkCommandLineParser::ctkCommandLineParser(QSettings* settings, QObject* newParent) :
+    Superclass(newParent)
 {
   this->Internal = new ctkInternal(settings);
 }

+ 12 - 4
Libs/Core/ctkCommandLineParser.h

@@ -81,10 +81,17 @@ class QSettings;
  * }
  * \endcode
  */
-class CTK_CORE_EXPORT ctkCommandLineParser
+class CTK_CORE_EXPORT ctkCommandLineParser : public QObject
 {
+  Q_OBJECT
+  Q_PROPERTY(QString errorString READ errorString)
+  Q_PROPERTY(QStringList unparsedArguments READ unparsedArguments)
+  Q_PROPERTY(bool settingsEnabled READ settingsEnabled)
+
 public:
 
+  typedef QObject Superclass;
+
   /**
    * Constructs a parser instance.
    *
@@ -97,7 +104,8 @@ public:
    *
    * @param settings A QSettings instance which should be used.
    */
-  ctkCommandLineParser(QSettings* settings = 0);
+  ctkCommandLineParser(QObject* newParent = 0);
+  ctkCommandLineParser(QSettings* settings, QObject* newParent = 0);
 
   ~ctkCommandLineParser();
   
@@ -159,7 +167,7 @@ public:
    * @return <code>true</code> if the argument was added, <code>false</code>
    *         otherwise.
    */
-  bool argumentAdded(const QString& argument) const;
+  Q_INVOKABLE bool argumentAdded(const QString& argument) const;
 
   /**
    * Checks if the given argument has been parsed successfully by a previous
@@ -169,7 +177,7 @@ public:
    * @return <code>true</code> if the argument was parsed, <code>false</code>
    *         otherwise.
    */
-  bool argumentParsed(const QString& argument) const;
+  Q_INVOKABLE bool argumentParsed(const QString& argument) const;
 
   /**
    * Adds a command line argument. An argument can have a long name