From b1635798184e54df7e34e3d5913101486b7cfc6b Mon Sep 17 00:00:00 2001
From: Otmane Lahlou <otmane.lahlou@c-s.fr>
Date: Tue, 27 Sep 2011 16:05:17 +0200
Subject: [PATCH] ENH: - add a pointer to the parameter to be able to modify
 its activity status      - connect parameterBase slots to signal emitted from
 two checkbox,        then two slots are available, one handling the signal
 related to a paremeter        Group checkbox, and the other slot is relative
 to a simple parameter relative       checkbox

---
 .../otbWrapperQtWidgetParameterBase.cxx       | 62 ++++++++++++++++++-
 .../otbWrapperQtWidgetParameterBase.h         |  8 ++-
 2 files changed, 67 insertions(+), 3 deletions(-)

diff --git a/Code/Wrappers/QtWidget/otbWrapperQtWidgetParameterBase.cxx b/Code/Wrappers/QtWidget/otbWrapperQtWidgetParameterBase.cxx
index 20997b7dba..071689ac02 100644
--- a/Code/Wrappers/QtWidget/otbWrapperQtWidgetParameterBase.cxx
+++ b/Code/Wrappers/QtWidget/otbWrapperQtWidgetParameterBase.cxx
@@ -22,8 +22,8 @@ namespace otb
 namespace Wrapper
 {
 
-QtWidgetParameterBase::QtWidgetParameterBase(QtWidgetModel* m)
-  : m_Model(m)
+QtWidgetParameterBase::QtWidgetParameterBase(Parameter * param, QtWidgetModel* m)
+  : m_Param(param), m_Model(m)
 {
 }
 
@@ -51,6 +51,64 @@ QtWidgetModel* QtWidgetParameterBase::GetModel()
   return m_Model;
 }
 
+// Slot connected to the signal emitted the checkBox relative to
+// current widget
+void QtWidgetParameterBase::SetValue( int value )
+{
+  switch(value)
+    {
+    case Qt::Unchecked:
+      this->setEnabled(false);
+      m_Param->SetChecked(false);
+      m_Param->SetActive(false);
+      break;
+    case Qt::PartiallyChecked:
+      break;
+    case Qt::Checked:
+      this->setEnabled(true);
+      m_Param->SetChecked(true);
+      m_Param->SetActive(true);
+      break;
+    }
+}
+
+// A slot connected to a signal emitted by a ParameterGroup
+// we need to modify the children availabitily status
+void QtWidgetParameterBase::SetValue( bool v)
+{
+  // Update the Group status
+  this->setEnabled(v);
+
+  // Update iteratively the children status
+  for (unsigned int idx = 0; idx < m_Param->GetChildrenList().size(); ++idx)
+    {
+    this->ProcessChild(m_Param->GetChildrenList()[idx], v);
+    }
 }
 
+// Activate iteratively  the children
+void QtWidgetParameterBase::ProcessChild(Parameter* currentNode, bool status)
+{
+  // Activate the current node if it was checked
+  if ( currentNode->IsChecked() && status)
+    {
+    currentNode->SetActive(status);
+    }
+
+  // If the status is false (deactivating) deactivate all the children
+  // tree
+  if (!status)
+    {
+    currentNode->SetActive(status);
+    }
+
+  unsigned int counter = 0;
+  while(counter < currentNode->GetChildrenList().size())
+    {
+    this->ProcessChild(currentNode->GetChildrenList()[counter], status);
+    ++counter;
+    }
+}
+
+}
 }
diff --git a/Code/Wrappers/QtWidget/otbWrapperQtWidgetParameterBase.h b/Code/Wrappers/QtWidget/otbWrapperQtWidgetParameterBase.h
index fcea90caf5..d699a832c6 100644
--- a/Code/Wrappers/QtWidget/otbWrapperQtWidgetParameterBase.h
+++ b/Code/Wrappers/QtWidget/otbWrapperQtWidgetParameterBase.h
@@ -34,13 +34,15 @@ class QtWidgetParameterBase : public QWidget
 {
   Q_OBJECT
 public:
-  QtWidgetParameterBase(QtWidgetModel*);
+  QtWidgetParameterBase(Parameter *, QtWidgetModel*);
   virtual ~QtWidgetParameterBase();
 
   void CreateWidget();
 
 public slots:
   void UpdateGUI();
+  void SetValue( int value );
+  void SetValue( bool v );
 
 protected slots:
   void ParameterChanged(const QString& key);
@@ -48,6 +50,8 @@ protected slots:
 protected:
   QtWidgetModel* GetModel();
 
+  virtual void ProcessChild(Parameter * currentNode, bool status);
+
 private:
   QtWidgetParameterBase(const QtWidgetParameterBase&); //purposely not implemented
   void operator=(const QtWidgetParameterBase&); //purposely not implemented
@@ -57,6 +61,8 @@ private:
   virtual void DoCreateWidget() = 0;
 
   QtWidgetModel* m_Model;
+
+  Parameter*      m_Param;
 };
 
 
-- 
GitLab