From 4b3a0fe77c0303240f4204fd39d07730341e7cc0 Mon Sep 17 00:00:00 2001
From: Otmane Lahlou <otmane.lahlou@c-s.fr>
Date: Tue, 27 Sep 2011 16:07:53 +0200
Subject: [PATCH] ENH: add checkbox to activate or not the parameters

---
 .../otbWrapperQtWidgetParameterGroup.cxx      | 48 +++++++++++++++++--
 1 file changed, 45 insertions(+), 3 deletions(-)

diff --git a/Code/Wrappers/QtWidget/otbWrapperQtWidgetParameterGroup.cxx b/Code/Wrappers/QtWidget/otbWrapperQtWidgetParameterGroup.cxx
index e73f9cf3e8..bd22325738 100644
--- a/Code/Wrappers/QtWidget/otbWrapperQtWidgetParameterGroup.cxx
+++ b/Code/Wrappers/QtWidget/otbWrapperQtWidgetParameterGroup.cxx
@@ -26,7 +26,7 @@ namespace Wrapper
 {
 
 QtWidgetParameterGroup::QtWidgetParameterGroup(ParameterGroup::Pointer paramList, QtWidgetModel* m)
-: QtWidgetParameterBase(m),
+: QtWidgetParameterBase(paramList, m),
   m_ParamList(paramList)
 {
 }
@@ -63,10 +63,42 @@ void QtWidgetParameterGroup::DoCreateWidget()
 
       if (paramAsGroup == 0 && paramAsChoice == 0)
         {
+        // Label (col 0)
         QWidget* label = new QtWidgetParameterLabel( param );
-        gridLayout->addWidget(label, i, 0);
+        gridLayout->addWidget(label, i, 1);
+
+        // Parameter Widget (col 2)
         QtWidgetParameterBase* specificWidget = QtWidgetParameterFactory::CreateQtWidget( param, GetModel() );
-        gridLayout->addWidget(specificWidget, i, 1);
+        gridLayout->addWidget(specificWidget, i, 2 );
+
+        // CheckBox (col 1)
+        QCheckBox * checkBox = new QCheckBox;
+        connect(checkBox, SIGNAL(stateChanged(int)), specificWidget, SLOT(SetValue(int)));
+        
+        if (param->IsRoot())
+           {
+          // if Mandatory make the checkbox checked and deactivated
+          if (param->GetMandatory())
+            {
+            checkBox->setCheckState(Qt::Checked);
+            checkBox->setEnabled(false);
+            specificWidget->setEnabled(true);
+            }
+          else
+            {
+            checkBox->setCheckState(Qt::Unchecked);
+            checkBox->setEnabled(true);
+            specificWidget->setEnabled(false);
+            }
+          }
+        else
+          {
+          // If this widget belongs to a Group, make it disabled by
+          // defaut
+          specificWidget->setEnabled(false);
+          }
+        gridLayout->addWidget(checkBox, i, 0);
+
         m_WidgetList.push_back(specificWidget);
         }
       else
@@ -77,6 +109,14 @@ void QtWidgetParameterGroup::DoCreateWidget()
         vboxLayout->addWidget(specificWidget);
         QGroupBox* group = new QGroupBox;
         group->setLayout(vboxLayout);
+
+        // Make the paramter Group checkable when it is not mandatory
+        if (!param->GetMandatory() )
+          {
+          group->setCheckable(true);
+          }
+        connect(group, SIGNAL(clicked(bool)), specificWidget, SLOT(SetValue(bool)));
+
         group->setTitle(param->GetName());
         gridLayout->addWidget(group, i, 0, 1, -1);
 
@@ -88,5 +128,7 @@ void QtWidgetParameterGroup::DoCreateWidget()
   this->setLayout(gridLayout);
 }
 
+
+
 }
 }
-- 
GitLab