Skip to content
Snippets Groups Projects
Commit 058fac0b authored by Julien Malik's avatar Julien Malik
Browse files

ENH: avoid multiple slots to handle the activation state

parent e4c2f472
No related branches found
No related tags found
No related merge requests found
......@@ -53,60 +53,19 @@ QtWidgetModel* QtWidgetParameterBase::GetModel()
// Slot connected to the signal emitted the checkBox relative to
// current widget
void QtWidgetParameterBase::SetActivationState( int value )
void QtWidgetParameterBase::SetActivationState( bool value )
{
switch(value)
if (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;
this->setEnabled(true);
m_Param->SetChecked(true);
m_Param->SetActive(true);
}
}
// 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())
else
{
this->ProcessChild(currentNode->GetChildrenList()[counter], status);
++counter;
this->setEnabled(false);
m_Param->SetChecked(false);
m_Param->SetActive(false);
}
}
......
......@@ -41,8 +41,7 @@ public:
public slots:
void UpdateGUI();
void SetActivationState( int value );
void SetValue( bool v );
virtual void SetActivationState( bool value );
protected slots:
void ParameterChanged(const QString& key);
......@@ -50,7 +49,6 @@ protected slots:
protected:
QtWidgetModel* GetModel();
virtual void ProcessChild(Parameter * currentNode, bool status);
private:
QtWidgetParameterBase(const QtWidgetParameterBase&); //purposely not implemented
......
......@@ -73,7 +73,7 @@ void QtWidgetParameterGroup::DoCreateWidget()
// CheckBox (col 1)
QCheckBox * checkBox = new QCheckBox;
connect(checkBox, SIGNAL(stateChanged(int)), specificWidget, SLOT(SetActivationState(int)));
connect(checkBox, SIGNAL(clicked(bool)), specificWidget, SLOT(SetActivationState(bool)));
if (param->IsRoot())
{
......@@ -115,7 +115,7 @@ void QtWidgetParameterGroup::DoCreateWidget()
{
group->setCheckable(true);
}
connect(group, SIGNAL(clicked(bool)), specificWidget, SLOT(SetValue(bool)));
connect(group, SIGNAL(clicked(bool)), specificWidget, SLOT(SetActivationState(bool)));
group->setTitle(param->GetName());
gridLayout->addWidget(group, i, 0, 1, -1);
......@@ -129,6 +129,47 @@ void QtWidgetParameterGroup::DoCreateWidget()
}
// Slot connected to the signal emitted the checkBox relative to
// current widget
void QtWidgetParameterGroup::SetActivationState( bool value )
{
// First call the superclass implementation
this->QtWidgetParameterBase::SetActivationState(value);
// Update the Group status
this->setEnabled(value);
// Update iteratively the children status
for (unsigned int idx = 0; idx < m_ParamList->GetChildrenList().size(); ++idx)
{
this->ProcessChild(m_ParamList->GetChildrenList()[idx], value);
}
}
// Activate iteratively the children
void QtWidgetParameterGroup::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;
}
}
}
}
......@@ -37,6 +37,9 @@ public:
QtWidgetParameterGroup(ParameterGroup::Pointer, QtWidgetModel*);
virtual ~QtWidgetParameterGroup();
public slots:
virtual void SetActivationState( bool value );
private:
QtWidgetParameterGroup(const QtWidgetParameterGroup&); //purposely not implemented
void operator=(const QtWidgetParameterGroup&); //purposely not implemented
......@@ -45,6 +48,8 @@ private:
virtual void DoUpdateGUI();
virtual void ProcessChild(Parameter * currentNode, bool status);
ParameterGroup::Pointer m_ParamList;
typedef std::vector<QtWidgetParameterBase*> WidgetListType;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment