From afdbc53b750304c59c6ca8126967a771ca09c91f Mon Sep 17 00:00:00 2001
From: Julien Malik <julien.malik@c-s.fr>
Date: Sun, 19 Jun 2011 17:30:33 +0200
Subject: [PATCH] ENH: handle groups

---
 Code/Wrappers/PyQt/otbapp/widgets.py | 29 ++++++++++++++++++++++------
 Example/otbTestApplication.cxx       | 21 +++++++++++++-------
 2 files changed, 37 insertions(+), 13 deletions(-)

diff --git a/Code/Wrappers/PyQt/otbapp/widgets.py b/Code/Wrappers/PyQt/otbapp/widgets.py
index 3042def38d..1b8dacf326 100644
--- a/Code/Wrappers/PyQt/otbapp/widgets.py
+++ b/Code/Wrappers/PyQt/otbapp/widgets.py
@@ -309,7 +309,6 @@ class QParameterGroup(QParameterBase):
 
     def DoCreateWidget(self):
         
-        form = QtGui.QFormLayout()
         
         defaultWidget = QParameterInt
         paramTypeToWidget = {
@@ -332,14 +331,32 @@ class QParameterGroup(QParameterBase):
 
         app = self.GetModel().GetApplication()
         if self._paramKey:
-            keys = [key for key in app.GetParametersKeys(True) if key and key.startswith(self._paramKey)]
+            keys = [key for key in app.GetParametersKeys(True) if key and key.startswith(self._paramKey + '.')]
         else:
             keys = app.GetParametersKeys(False)
-            
+        print 'keys ' + str(keys)
+        
+        form = QtGui.QFormLayout()
         for key in keys:
             widgetClass = paramTypeToWidget[app.GetParameterType(key)]
             w = widgetClass(self._model, key)
             w.CreateWidget()
-            form.addRow( app.GetParameterName(key), w )
-        
-        self.setLayout(form)
+
+            if widgetClass is not QParameterGroup:
+                print " form.addRow(w"
+                form.addRow( app.GetParameterName(key), w )
+            else:
+                print " form.addWidget(w"
+                form.addRow(w)
+
+        if self._paramKey:
+           # not the root group
+           group = QtGui.QGroupBox()
+           group.setTitle( app.GetParameterName(self._paramKey) )
+           group.setLayout(form)
+           
+           layout = QtGui.QHBoxLayout()
+           layout.addWidget(group)
+           self.setLayout(layout)
+        else:
+            self.setLayout(form)
diff --git a/Example/otbTestApplication.cxx b/Example/otbTestApplication.cxx
index 3427ac8a40..0c690fdbaf 100644
--- a/Example/otbTestApplication.cxx
+++ b/Example/otbTestApplication.cxx
@@ -57,12 +57,7 @@ private:
     AddParameter(ParameterType_String, "string", "String");
     AddParameter(ParameterType_Filename, "filename", "File name");
     AddParameter(ParameterType_Directory, "directory", "Directory name");
-    AddParameter(ParameterType_InputImage, "inputimage", "Input Image");
-    AddParameter(ParameterType_InputComplexImage, "inputcompleximage", "Input Complex Image");
-    AddParameter(ParameterType_InputVectorData, "inputvectordata", "Input Vector Data");
-    AddParameter(ParameterType_OutputImage, "outputimage", "Output Image");
-    AddParameter(ParameterType_OutputVectorData, "outputvectordata", "Output Vector Data");
-    AddParameter(ParameterType_Radius, "radius", "Radius");
+
 
     AddParameter(ParameterType_Choice, "choice", "Choice");
     AddChoice("choice.choice1", "Choice 1");
@@ -70,12 +65,24 @@ private:
     AddChoice("choice.choice3", "Choice 3");
     AddParameter(ParameterType_Float,  "choice.choice1.floatchoice1", "Float of choice1");
     SetParameterFloat("choice.choice1.floatchoice1",   0.125);
+//  Test a choice without associated parameter
 //    AddParameter(ParameterType_Float,  "choice.choice2.floatchoice2", "Float of choice2");
 //    SetParameterFloat("choice.choice2.floatchoice2",   1.0);
     AddParameter(ParameterType_Float,  "choice.choice3.floatchoice3", "Float of choice3");
     SetParameterFloat("choice.choice3.floatchoice3",   5.0);
 
-    //AddParameter(ParameterType_Group, "group", "Group");
+
+    AddParameter(ParameterType_Group, "ingroup", "Input Group");
+    AddParameter(ParameterType_Int,  "ingroup.integer", "Integer of Group");
+    AddParameter(ParameterType_InputImage, "ingroup.inputimage", "Input Image");
+    AddParameter(ParameterType_InputComplexImage, "ingroup.inputcompleximage", "Input Complex Image");
+    AddParameter(ParameterType_InputVectorData, "ingroup.inputvectordata", "Input Vector Data");
+
+    AddParameter(ParameterType_Group, "outgroup", "Output Group");
+    AddParameter(ParameterType_OutputImage, "outgroup.outputimage", "Output Image");
+    AddParameter(ParameterType_OutputVectorData, "outgroup.outputvectordata", "Output Vector Data");
+
+    AddParameter(ParameterType_Radius, "radius", "Radius");
   }
 
   void DoUpdateParameters()
-- 
GitLab