Sfoglia il codice sorgente

Merge branch 'cli-module-support'

MattClarkson 12 anni fa
parent
commit
aae9436a76

+ 8 - 0
Libs/CommandLineModules/Core/ctkCmdLineModuleDescription.cpp

@@ -65,6 +65,14 @@ QString ctkCmdLineModuleDescription::title() const
   return d->Title;
 }
 
+
+//----------------------------------------------------------------------------
+QString ctkCmdLineModuleDescription::categoryDotTitle() const
+{
+  return this->category() + "." + this->title();
+}
+
+
 //----------------------------------------------------------------------------
 QString ctkCmdLineModuleDescription::description() const
 {

+ 5 - 0
Libs/CommandLineModules/Core/ctkCmdLineModuleDescription.h

@@ -66,6 +66,11 @@ public:
   QString title() const;
 
   /**
+   * @brief Helper method that returns the category followed by a dot followed by the title.
+   */
+  QString categoryDotTitle() const;
+
+  /**
    * @brief Returns the title, derived from the \code <description> \endcode tag.
    */
   QString description() const;

+ 59 - 19
Libs/CommandLineModules/Frontend/QtGui/Resources/ctkCmdLineModuleXmlToQtUi.xsl

@@ -49,10 +49,13 @@
   <xsl:param name="floatValueProperty">value</xsl:param>
   <xsl:param name="pointValueProperty">coordinates</xsl:param>
   <xsl:param name="regionValueProperty">coordinates</xsl:param>
-  <xsl:param name="imageValueProperty">currentPath</xsl:param>
-  <xsl:param name="fileValueProperty">currentPath</xsl:param>
+  <xsl:param name="imageInputValueProperty">currentPath</xsl:param>
+  <xsl:param name="imageOutputValueProperty">currentPath</xsl:param>
+  <xsl:param name="fileInputValueProperty">currentPath</xsl:param>
+  <xsl:param name="fileOutputValueProperty">currentPath</xsl:param>
   <xsl:param name="directoryValueProperty">currentPath</xsl:param>
-  <xsl:param name="geometryValueProperty">currentPath</xsl:param>
+  <xsl:param name="geometryInputValueProperty">currentPath</xsl:param>
+  <xsl:param name="geometryOutputValueProperty">currentPath</xsl:param>
   <xsl:param name="vectorValueProperty">text</xsl:param>
   <xsl:param name="enumerationValueProperty">currentEnumeration</xsl:param>
 
@@ -80,6 +83,7 @@
        (or be convertible to it). -->
   <xsl:function name="ctk:mapTypeToQtValueProperty">
     <xsl:param name="cliType"/>
+    <xsl:param name="cliChannel"/> 
     <xsl:choose>
       <xsl:when test="$cliType='boolean'"><xsl:value-of select="$booleanValueProperty"/></xsl:when>
       <xsl:when test="$cliType='integer'"><xsl:value-of select="$integerValueProperty"/></xsl:when>
@@ -87,10 +91,13 @@
       <xsl:when test="$cliType='double'"><xsl:value-of select="$floatValueProperty"/></xsl:when>
       <xsl:when test="$cliType='point'"><xsl:value-of select="$pointValueProperty"/></xsl:when>
       <xsl:when test="$cliType='region'"><xsl:value-of select="$regionValueProperty"/></xsl:when>
-      <xsl:when test="$cliType='image'"><xsl:value-of select="$imageValueProperty"/></xsl:when>
-      <xsl:when test="$cliType='file'"><xsl:value-of select="$fileValueProperty"/></xsl:when>
+      <xsl:when test="$cliType='image' and $cliChannel='input'"><xsl:value-of select="$imageInputValueProperty"/></xsl:when>
+      <xsl:when test="$cliType='image' and $cliChannel='output'"><xsl:value-of select="$imageOutputValueProperty"/></xsl:when>
+      <xsl:when test="$cliType='file' and $cliChannel='input'"><xsl:value-of select="$fileInputValueProperty"/></xsl:when>
+      <xsl:when test="$cliType='file' and $cliChannel='output'"><xsl:value-of select="$fileOutputValueProperty"/></xsl:when>
       <xsl:when test="$cliType='directory'"><xsl:value-of select="$directoryValueProperty"/></xsl:when>
-      <xsl:when test="$cliType='geometry'"><xsl:value-of select="$geometryValueProperty"/></xsl:when>
+      <xsl:when test="$cliType='geometry' and $cliChannel='input'"><xsl:value-of select="$geometryInputValueProperty"/></xsl:when>
+      <xsl:when test="$cliType='geometry' and $cliChannel='output'"><xsl:value-of select="$geometryOutputValueProperty"/></xsl:when>      
       <xsl:when test="$cliType='integer-vector'"><xsl:value-of select="$vectorValueProperty"/></xsl:when>
       <xsl:when test="$cliType='double-vector'"><xsl:value-of select="$vectorValueProperty"/></xsl:when>
       <xsl:when test="$cliType='float-vector'"><xsl:value-of select="$vectorValueProperty"/></xsl:when>
@@ -140,9 +147,25 @@
   <!-- Set the default value by generating a Qt widget specific property which holds
        the current value -->
   <xsl:template match="default">
-    <property name="{ctk:mapTypeToQtValueProperty(name(..))}">
-      <xsl:element name="{ctk:mapTypeToQtDesigner(name(..))}"><xsl:value-of select="text()"/></xsl:element>
-    </property>
+    <xsl:choose>
+      <xsl:when test="../channel">
+        <xsl:if test="../channel/text()='output'">
+          <property name="{ctk:mapTypeToQtValueProperty(name(..),'output')}">
+            <xsl:element name="{ctk:mapTypeToQtDesigner(name(..))}"><xsl:value-of select="text()"/></xsl:element>
+          </property>
+        </xsl:if>
+        <xsl:if test="../channel/text()='input'">
+          <property name="{ctk:mapTypeToQtValueProperty(name(..),'input')}">
+            <xsl:element name="{ctk:mapTypeToQtDesigner(name(..))}"><xsl:value-of select="text()"/></xsl:element>
+          </property>
+        </xsl:if>
+      </xsl:when>
+      <xsl:otherwise>
+        <property name="{ctk:mapTypeToQtValueProperty(name(..),'dummy')}">
+          <xsl:element name="{ctk:mapTypeToQtDesigner(name(..))}"><xsl:value-of select="text()"/></xsl:element>
+        </property>
+      </xsl:otherwise>
+    </xsl:choose>
   </xsl:template>
 
   <!-- Set Qt widget (spinbox) specific properties for applying constraints of scalar parameters -->
@@ -176,7 +199,7 @@
   </xsl:template>
 
   <!-- A named template for adding properties common to all Qt widgets -->
-  <xsl:template name="commonWidgetProperties">
+  <xsl:template name="commonWidgetProperties">  
     <xsl:apply-templates select="description"/> <!-- tooltip -->
     <xsl:if test="@hidden='true'"> <!-- widget visibility -->
       <property  name="visible">
@@ -190,9 +213,20 @@
       </property>
     </xsl:if>
     <property name="parameter:valueProperty"> <!-- property name containing current value -->
-      <string><xsl:value-of select="ctk:mapTypeToQtValueProperty(name())"/></string>
-    </property>
-
+    <xsl:choose>
+      <xsl:when test="channel">      
+        <xsl:if test="channel/text()='output'">
+          <string><xsl:value-of select="ctk:mapTypeToQtValueProperty(name(),'output')"/></string>
+        </xsl:if>
+        <xsl:if test="channel/text()='input'">
+          <string><xsl:value-of select="ctk:mapTypeToQtValueProperty(name(),'input')"/></string>
+        </xsl:if>
+      </xsl:when>      
+      <xsl:otherwise>
+        <string><xsl:value-of select="ctk:mapTypeToQtValueProperty(name(),'dummy')"/></string>
+      </xsl:otherwise> 
+    </xsl:choose>
+    </property>       
     <!-- add additional (optional) information as properties -->
     <xsl:apply-templates select="default"/>
     <xsl:apply-templates select="constraints"/>
@@ -256,8 +290,14 @@
         <property name="checked">
           <bool><xsl:value-of select="not(@advanced)"></xsl:value-of></bool>
         </property>
-        <layout class="QGridLayout">
-          <xsl:apply-templates select="./description/following-sibling::*"/>
+        <layout class="QVBoxLayout" name="paramContainerLayout:{$groupLabel}">
+          <item>
+            <widget class="QWidget" name="paramContainer:{$groupLabel}">
+              <layout class="QGridLayout">
+                <xsl:apply-templates select="./description/following-sibling::*"/>
+              </layout>            
+            </widget>
+          </item>
         </layout>
       </widget>
     </item>
@@ -382,7 +422,7 @@
             <xsl:call-template name="commonWidgetProperties"/>
             <xsl:call-template name="createQtDesignerStringListProperty"/>
             <property name="filters">
-              <set>ctkPathLineEdit::Files</set>
+              <set>ctkPathLineEdit::Files,ctkPathLineEdit::Readable</set>
             </property>
           </widget>
         </xsl:when>
@@ -391,7 +431,7 @@
             <xsl:call-template name="commonWidgetProperties"/>
             <xsl:call-template name="createQtDesignerStringListProperty"/>
             <property name="filters">
-              <set>ctkPathLineEdit::Files</set>
+              <set>ctkPathLineEdit::Files,ctkPathLineEdit::Writable</set>
             </property>
           </widget>
         </xsl:otherwise>
@@ -414,7 +454,7 @@
             <xsl:call-template name="commonWidgetProperties"/>
             <xsl:call-template name="createQtDesignerStringListProperty"/>
             <property name="filters">
-              <set>ctkPathLineEdit::Files</set>
+              <set>ctkPathLineEdit::Files,ctkPathLineEdit::Readable</set>
             </property>
           </widget>
         </xsl:when>
@@ -423,7 +463,7 @@
             <xsl:call-template name="commonWidgetProperties"/>
             <xsl:call-template name="createQtDesignerStringListProperty"/>
             <property name="filters">
-              <set>ctkPathLineEdit::Files</set>
+              <set>ctkPathLineEdit::Files,ctkPathLineEdit::Writable</set>
             </property>
           </widget>
         </xsl:otherwise>

+ 14 - 0
Libs/CommandLineModules/Frontend/QtGui/ctkCmdLineModuleFrontendQtGui.cpp

@@ -206,3 +206,17 @@ QList<QString> ctkCmdLineModuleFrontendQtGui::parameterNames() const
   }
   return d->ParameterNames;
 }
+
+
+//-----------------------------------------------------------------------------
+void ctkCmdLineModuleFrontendQtGui::setParameterContainerEnabled(const bool& enabled)
+{
+  if (d->Widget == 0) return;
+
+  ctkCmdLineModuleObjectTreeWalker walker(d->Widget);
+  while(walker.readNextParameterContainer())
+  {
+    QVariant value(enabled);
+    walker.setValue(value, "enabled");
+  }
+}

+ 15 - 6
Libs/CommandLineModules/Frontend/QtGui/ctkCmdLineModuleFrontendQtGui.h

@@ -81,15 +81,15 @@ struct ctkCmdLineModuleFrontendQtGuiPrivate;
  * <tr><td>float-enumeration</td><td>enumWidget</td><td>QComboBox</td><td>enumerationValueProperty</td><td>currentEnumeration</td></tr>
  * <tr><td>double-enumeration</td><td>enumWidget</td><td>QComboBox</td><td>enumerationValueProperty</td><td>currentEnumeration</td></tr>
  * <tr><td>string-enumeration</td><td>enumWidget</td><td>QComboBox</td><td>enumerationValueProperty</td><td>currentEnumeration</td></tr>
- * <tr><td>file (input channel)</td><td>fileInputWidget</td><td>ctkPathLineEdit</td><td>fileValueProperty</td><td>currentPath</td></tr>
- * <tr><td>file (output channel)</td><td>fileOutputWidget</td><td>ctkPathLineEdit</td><td>fileValueProperty</td><td>currentPath</td></tr>
- * <tr><td>geometry (input channel)</td><td>fileInputWidget</td><td>ctkPathLineEdit</td><td>fileValueProperty</td><td>currentPath</td></tr>
- * <tr><td>geometry (output channel)</td><td>fileOutputWidget</td><td>ctkPathLineEdit</td><td>fileValueProperty</td><td>currentPath</td></tr>
+ * <tr><td>file (input channel)</td><td>fileInputWidget</td><td>ctkPathLineEdit</td><td>fileInputValueProperty</td><td>currentPath</td></tr>
+ * <tr><td>file (output channel)</td><td>fileOutputWidget</td><td>ctkPathLineEdit</td><td>fileOutputValueProperty</td><td>currentPath</td></tr>
+ * <tr><td>geometry (input channel)</td><td>fileInputWidget</td><td>ctkPathLineEdit</td><td>geometryInputValueProperty</td><td>currentPath</td></tr>
+ * <tr><td>geometry (output channel)</td><td>fileOutputWidget</td><td>ctkPathLineEdit</td><td>geometryOutputValueProperty</td><td>currentPath</td></tr>
  * <tr><td>directory</td><td>directoryWidget</td><td>ctkPathLineEdit</td><td>directoryValueProperty</td><td>currentPath</td></tr>
  * <tr><td>point</td><td>pointWidget</td><td>ctkCoordinatesWidget</td><td>pointValueProperty</td><td>coordinates</td></tr>
  * <tr><td>region</td><td>pointWidget</td><td>ctkCoordinatesWidget</td><td>pointValueProperty</td><td>coordinates</td></tr>
- * <tr><td>image (input channel)</td><td>imageInputWidget</td><td>ctkPathLineEdit</td><td>imageValueProperty</td><td>currentPath</td></tr>
- * <tr><td>image (output channel)</td><td>imageOutputWidget</td><td>ctkPathLineEdit</td><td>imageValueProperty</td><td>currentPath</td></tr>
+ * <tr><td>image (input channel)</td><td>imageInputWidget</td><td>ctkPathLineEdit</td><td>imageInputValueProperty</td><td>currentPath</td></tr>
+ * <tr><td>image (output channel)</td><td>imageOutputWidget</td><td>ctkPathLineEdit</td><td>imageOutputValueProperty</td><td>currentPath</td></tr>
  * <tr><td>[main container]</td><td>executableWidget</td><td>QWidget</td><td>n/a</td><td>n/a</td></tr>
  * <tr><td>[group container]</td><td>parametersWidget</td><td>ctkCollapsibleGroupBox</td><td>n/a</td><td>n/a</td></tr>
  * <tr><td>[unknown type]</td><td>unsupportedWidget</td><td>QLabel</td><td>n/a</td><td>n/a</td></tr>
@@ -144,6 +144,15 @@ public:
 
   virtual QList<QString> parameterNames() const;
 
+  /**
+   * \brief There is a container QWidget within each group box, so you can
+   * set the container widget to enabled/disabled, thereby affecting all
+   * child widgets, without overwriting the enabled/disabled status of the
+   * child widget.
+   * @param enabled if true then enabled else disabled
+   */
+  virtual void setParameterContainerEnabled(const bool& enabled);
+
 protected:
 
   /**

+ 25 - 3
Libs/CommandLineModules/Frontend/QtGui/ctkCmdLineModuleObjectTreeWalker.cpp

@@ -29,6 +29,7 @@ namespace {
 
 static QString PREFIX_EXECUTABLE = "executable:";
 static QString PREFIX_PARAMETER_GROUP = "paramGroup:";
+static QString PREFIX_PARAMETER_CONTAINER = "paramContainer:";
 static QString PREFIX_PARAMETER = "parameter:";
 
 }
@@ -72,6 +73,14 @@ bool ctkCmdLineModuleObjectTreeWalker::isParameterGroup() const
   return CurrentToken == ParameterGroup;
 }
 
+
+//----------------------------------------------------------------------------
+bool ctkCmdLineModuleObjectTreeWalker::isParameterContainer() const
+{
+  return CurrentToken == ParameterContainer;
+}
+
+
 //----------------------------------------------------------------------------
 bool ctkCmdLineModuleObjectTreeWalker::isParameter() const
 {
@@ -86,6 +95,7 @@ QString ctkCmdLineModuleObjectTreeWalker::name() const
   {
   case Executable: return CurrentObject->objectName().mid(PREFIX_EXECUTABLE.size());
   case ParameterGroup: return CurrentObject->objectName().mid(PREFIX_PARAMETER_GROUP.size());
+  case ParameterContainer: return CurrentObject->objectName().mid(PREFIX_PARAMETER_CONTAINER.size());
   case Parameter: return CurrentObject->objectName().mid(PREFIX_PARAMETER.size());
   default: return QString();
   }
@@ -99,6 +109,7 @@ QString ctkCmdLineModuleObjectTreeWalker::label() const
   {
   case Executable: return CurrentObject->objectName().mid(PREFIX_EXECUTABLE.size());
   case ParameterGroup: return property("title").toString();
+  case ParameterContainer: return property("name").toString();
   case Parameter: return property("label").toString();
   default: return QString();
   }
@@ -224,21 +235,30 @@ ctkCmdLineModuleObjectTreeWalker::TokenType ctkCmdLineModuleObjectTreeWalker::re
 //----------------------------------------------------------------------------
 bool ctkCmdLineModuleObjectTreeWalker::readNextExecutable()
 {
-  while (!(readNext() == Executable || AtEnd));
+  while (!(readNext() == Executable || AtEnd)) ; // deliberately empty loop body
   return !AtEnd;
 }
 
 //----------------------------------------------------------------------------
 bool ctkCmdLineModuleObjectTreeWalker::readNextParameterGroup()
 {
-  while (!(readNext() == ParameterGroup || AtEnd));
+  while (!(readNext() == ParameterGroup || AtEnd)) ; // deliberately empty loop body
   return !AtEnd;
 }
 
+
+//----------------------------------------------------------------------------
+bool ctkCmdLineModuleObjectTreeWalker::readNextParameterContainer()
+{
+  while (!(readNext() == ParameterContainer || AtEnd)) ; // deliberately empty loop body
+  return !AtEnd;
+}
+
+
 //----------------------------------------------------------------------------
 bool ctkCmdLineModuleObjectTreeWalker::readNextParameter()
 {
-  while (!(readNext() == Parameter || AtEnd));
+  while (!(readNext() == Parameter || AtEnd)) ; // deliberately empty loop body
   return !AtEnd;
 }
 
@@ -258,6 +278,7 @@ QVariant ctkCmdLineModuleObjectTreeWalker::prefixedProperty(const QString& propN
   {
   case ctkCmdLineModuleObjectTreeWalker::Executable: prefixedName = PREFIX_EXECUTABLE + propName;
   case ctkCmdLineModuleObjectTreeWalker::ParameterGroup: prefixedName = PREFIX_PARAMETER_GROUP + propName;
+  case ctkCmdLineModuleObjectTreeWalker::ParameterContainer: prefixedName = PREFIX_PARAMETER_CONTAINER + propName;
   case ctkCmdLineModuleObjectTreeWalker::Parameter: prefixedName = PREFIX_PARAMETER + propName;
   default: ;
   }
@@ -273,6 +294,7 @@ ctkCmdLineModuleObjectTreeWalker::token(QObject* obj)
   QString name = obj->objectName();
   if (name.startsWith(PREFIX_EXECUTABLE)) return ctkCmdLineModuleObjectTreeWalker::Executable;
   if (name.startsWith(PREFIX_PARAMETER_GROUP)) return ctkCmdLineModuleObjectTreeWalker::ParameterGroup;
+  if (name.startsWith(PREFIX_PARAMETER_CONTAINER)) return ctkCmdLineModuleObjectTreeWalker::ParameterContainer;
   if (name.startsWith(PREFIX_PARAMETER)) return ctkCmdLineModuleObjectTreeWalker::Parameter;
   return ctkCmdLineModuleObjectTreeWalker::NoToken;
 }

+ 3 - 0
Libs/CommandLineModules/Frontend/QtGui/ctkCmdLineModuleObjectTreeWalker_p.h

@@ -42,6 +42,7 @@ public:
     NoToken,
     Executable,
     ParameterGroup,
+    ParameterContainer,
     Parameter
   };
 
@@ -54,6 +55,7 @@ public:
   bool atEnd() const;
 
   bool isParameterGroup() const;
+  bool isParameterContainer() const;
   bool isParameter() const;
 
   QString name() const;
@@ -74,6 +76,7 @@ public:
   TokenType readNext();
   bool readNextExecutable();
   bool readNextParameterGroup();
+  bool readNextParameterContainer();
   bool readNextParameter();
 
   TokenType tokenType() const;