From 0d7b0fbeea8cd20cd513528dc7dc9c4ec6fc2eda Mon Sep 17 00:00:00 2001
From: Julien Malik <julien.malik@c-s.fr>
Date: Sun, 24 Apr 2011 00:11:20 +0100
Subject: [PATCH] ENH: add choice subparameters management

---
 .../otbWrapperQtWidgetChoiceParameter.cxx     | 49 ++++++++++++++-----
 .../otbWrapperQtWidgetChoiceParameter.h       |  9 +++-
 .../otbWrapperQtWidgetParameterGroup.cxx      |  3 +-
 Example/Smoothing/otbSmoothing.cxx            | 19 +++++--
 4 files changed, 62 insertions(+), 18 deletions(-)

diff --git a/Code/Wrappers/QtWidget/otbWrapperQtWidgetChoiceParameter.cxx b/Code/Wrappers/QtWidget/otbWrapperQtWidgetChoiceParameter.cxx
index 6d4c96dbb7..5550f9ef51 100644
--- a/Code/Wrappers/QtWidget/otbWrapperQtWidgetChoiceParameter.cxx
+++ b/Code/Wrappers/QtWidget/otbWrapperQtWidgetChoiceParameter.cxx
@@ -17,6 +17,9 @@
 =========================================================================*/
 #include "otbWrapperQtWidgetChoiceParameter.h"
 
+#include "otbWrapperQtWidgetParameterLabel.h"
+#include "otbWrapperQtWidgetParameterFactory.h"
+
 namespace otb
 {
 namespace Wrapper
@@ -31,29 +34,52 @@ QtWidgetChoiceParameter::QtWidgetChoiceParameter(ChoiceParameter* param, QtWidge
 
 QtWidgetChoiceParameter::~QtWidgetChoiceParameter()
 {
-
 }
 
 void QtWidgetChoiceParameter::CreateWidget()
 {
-  // Set up input text edit
-  QHBoxLayout *hLayout = new QHBoxLayout;
-  hLayout->setSpacing(0);
-  hLayout->setContentsMargins(0,0,0,0);
+  m_ComboBox = new QComboBox;
+  m_ComboBox->setToolTip(m_ChoiceParam->GetDescription());
+
+  m_StackWidget = new QStackedWidget;
+
+  connect( m_ComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(SetValue(int)) );
+  connect( m_ComboBox, SIGNAL(currentIndexChanged(int)), m_StackWidget, SLOT(setCurrentIndex(int)) );
 
-  QComboBox* combobox = new QComboBox;
-  combobox->setToolTip(m_ChoiceParam->GetDescription());
 
   for (unsigned int i = 0; i < m_ChoiceParam->GetNbChoices(); ++i)
     {
     QString key = QString::fromStdString( m_ChoiceParam->GetChoiceKey(i) );
-    combobox->addItem( key, QVariant(key) );
+    m_ComboBox->addItem( key, QVariant(key) );
+
+    Parameter::Pointer param = m_ChoiceParam->GetChoiceAssociatedParameter(i);
+    if (param.IsNotNull())
+      {
+      std::cout << param->GetName() << std::endl;
+      QWidget* label = new QtWidgetParameterLabel( param );
+      QWidget* specificWidget = QtWidgetParameterFactory::CreateQtWidget( param, GetModel() );
+      QHBoxLayout* hbox = new QHBoxLayout;
+      hbox->addWidget(label);
+      hbox->addWidget(specificWidget);
+      QGroupBox* group = new QGroupBox;
+      group->setLayout(hbox);
+      m_StackWidget->addWidget(group);
+      }
     }
 
-  connect( combobox, SIGNAL(currentIndexChanged(int)), this, SLOT(SetValue(int)) );
+  m_VLayout = new QVBoxLayout;
+  m_VLayout->addWidget(m_ComboBox);
+  m_VLayout->addWidget(m_StackWidget);
+
+  m_VLayoutGroup = new QGroupBox;
+  m_VLayoutGroup->setLayout(m_VLayout);
+  m_VLayoutGroup->setFlat(true);
 
-  hLayout->addWidget(combobox);
-  this->setLayout(hLayout);
+  m_MainHLayout = new QHBoxLayout;
+  m_MainHLayout->setSpacing(0);
+  m_MainHLayout->setContentsMargins(0,0,0,0);
+  m_MainHLayout->addWidget(m_VLayoutGroup);
+  this->setLayout(m_MainHLayout);
 }
 
 void QtWidgetChoiceParameter::SetValue(int value)
@@ -61,6 +87,5 @@ void QtWidgetChoiceParameter::SetValue(int value)
   m_ChoiceParam->SetValue( value );
 }
 
-
 }
 }
diff --git a/Code/Wrappers/QtWidget/otbWrapperQtWidgetChoiceParameter.h b/Code/Wrappers/QtWidget/otbWrapperQtWidgetChoiceParameter.h
index d789021fce..21212ff6e4 100644
--- a/Code/Wrappers/QtWidget/otbWrapperQtWidgetChoiceParameter.h
+++ b/Code/Wrappers/QtWidget/otbWrapperQtWidgetChoiceParameter.h
@@ -48,8 +48,15 @@ protected:
 private:
   QtWidgetChoiceParameter(const QtWidgetChoiceParameter&); //purposely not implemented
   void operator=(const QtWidgetChoiceParameter&); //purposely not implemented
-};
 
+  QHBoxLayout*    m_MainHLayout;
+
+  QComboBox*      m_ComboBox;
+  QStackedWidget* m_StackWidget;
+
+  QVBoxLayout*    m_VLayout;
+  QGroupBox*      m_VLayoutGroup;
+};
 
 }
 }
diff --git a/Code/Wrappers/QtWidget/otbWrapperQtWidgetParameterGroup.cxx b/Code/Wrappers/QtWidget/otbWrapperQtWidgetParameterGroup.cxx
index 56f5908b1f..db7757d534 100644
--- a/Code/Wrappers/QtWidget/otbWrapperQtWidgetParameterGroup.cxx
+++ b/Code/Wrappers/QtWidget/otbWrapperQtWidgetParameterGroup.cxx
@@ -49,8 +49,7 @@ void QtWidgetParameterGroup::CreateWidget()
     QWidget* label = new QtWidgetParameterLabel( param );
     gridLayout->addWidget(label, i, 0);
     QWidget* specificWidget = QtWidgetParameterFactory::CreateQtWidget( param, GetModel() );
-    //if (specificWidget)
-      gridLayout->addWidget(specificWidget, i, 1);
+    gridLayout->addWidget(specificWidget, i, 1);
     }
 
   this->setLayout(gridLayout);
diff --git a/Example/Smoothing/otbSmoothing.cxx b/Example/Smoothing/otbSmoothing.cxx
index 9929677af2..4dd52d447a 100644
--- a/Example/Smoothing/otbSmoothing.cxx
+++ b/Example/Smoothing/otbSmoothing.cxx
@@ -49,9 +49,22 @@ void Smoothing::DoCreateParameters()
   smoothingType->SetName("Smoothing Type");
   smoothingType->SetKey("type");
 
-  smoothingType->AddChoice("Mean", 0);
-  smoothingType->AddChoice("Gaussian", 0);
-  smoothingType->AddChoice("Anisotropic Diffusion", 0);
+  otb::Wrapper::RadiusParameter::Pointer meanSmoothingRadius  = otb::Wrapper::RadiusParameter::New();
+  smoothingType->AddChoice("Mean", meanSmoothingRadius.GetPointer());
+
+  otb::Wrapper::RadiusParameter::Pointer gaussianSmoothingRadius  = otb::Wrapper::RadiusParameter::New();
+  smoothingType->AddChoice("Gaussian", gaussianSmoothingRadius.GetPointer());
+
+  otb::Wrapper::FloatParameter::Pointer aniDifTimeStep  = otb::Wrapper::FloatParameter::New();
+  aniDifTimeStep->SetName("Time Step");
+  aniDifTimeStep->SetKey("TimeStep");
+  otb::Wrapper::IntParameter::Pointer aniDifNbIter = otb::Wrapper::IntParameter::New();
+  aniDifTimeStep->SetName("Nb Iterations");
+  aniDifTimeStep->SetKey("NbIter");
+  otb::Wrapper::ParameterGroup::Pointer aniDifGroup = otb::Wrapper::ParameterGroup::New();
+  aniDifGroup->AddParameter(aniDifTimeStep.GetPointer());
+  aniDifGroup->AddParameter(aniDifNbIter.GetPointer());
+  smoothingType->AddChoice("Anisotropic Diffusion", aniDifGroup.GetPointer());
 
   ParameterGroup* params = GetParameterList();
   params->AddParameter(inImage.GetPointer());
-- 
GitLab