Commit a067c357 authored by Otmane Lahlou's avatar Otmane Lahlou
Browse files

ENH: add Reset button for NumericalParameter

     - Add new methods SetDefaultParameterInt and SetDefaultParameterFloat
       useful for setting default values in the method DoCreateParameters()
     - Add button Reset to each NumericalParameter, and connect this button
       to a slot Reset() setting the value to the default one if any, making
       the state HasUserValue and HasAutomaticValue to false
parent d3659af5
......@@ -156,7 +156,7 @@ private:
std::ostringstream oss;
oss << "Activate RPC sensor model estimation"<<std::endl;
oss << "Parameter is the number of control points per axis";
SetParameterDescription("rpc",oss.str().c_str());
//SetParameterDescription("rpc",oss.str().c_str());
MandatoryOff("rpc");
// Interpolators
......@@ -165,7 +165,7 @@ private:
AddChoice("interpolator.nn", "Nearest Neighbor");
AddChoice("interpolator.bco", "BCO");
AddParameter(ParameterType_Radius, "interpolator.bco.radius", "Radius");
SetParameterInt("interpolator.bco.radius", 2);
SetDefaultParameterInt("interpolator.bco.radius", 2);
// Built the Output Map Projection
AddParameter(ParameterType_Choice, "map", "Map Projection");
......@@ -178,12 +178,12 @@ private:
AddChoice("map.epsg","EPSG");
AddParameter(ParameterType_Int, "map.epsg.code", "EPSG Code");
SetParameterInt("map.epsg.code",32631);
SetDefaultParameterInt("map.epsg.code",32631);
SetParameterString("map", "epsg");
// Deformation Field Spacing
AddParameter(ParameterType_Float, "gridspacing", "Deformation Field Spacing");
SetParameterInt("gridspacing", 4.);
SetDefaultParameterFloat("gridspacing", 4.);
SetParameterDescription("gridspacing", "Generate a coarser deformation field with the given spacing");
MandatoryOff("gridspacing");
}
......@@ -223,7 +223,9 @@ private:
// Fill the Gui with the computed parameters
if (!HasUserValue("outputs.ulx"))
{
SetParameterFloat("outputs.ulx", genericRSEstimator->GetOutputOrigin()[0]);
}
if (!HasUserValue("outputs.uly"))
SetParameterFloat("outputs.uly", genericRSEstimator->GetOutputOrigin()[1]);
......
......@@ -419,6 +419,42 @@ void Application::SetParameterFloat(std::string parameter, float value)
}
}
void Application::SetDefaultParameterInt(std::string parameter, int value)
{
Parameter* param = GetParameterByKey(parameter);
if (dynamic_cast<IntParameter*>(param))
{
IntParameter* paramInt = dynamic_cast<IntParameter*>(param);
paramInt->SetDefaultValue(value);
paramInt->SetValue(value);
}
else if (dynamic_cast<FloatParameter*>(param))
{
FloatParameter* paramFloat = dynamic_cast<FloatParameter*>(param);
paramFloat->SetDefaultValue(static_cast<float>(value));
paramFloat->SetValue(static_cast<float>(value));
}
else if (dynamic_cast<RadiusParameter*>(param))
{
RadiusParameter* paramRadius = dynamic_cast<RadiusParameter*>(param);
paramRadius->SetDefaultValue(value);
paramRadius->SetValue(value);
}
}
void Application::SetDefaultParameterFloat(std::string parameter, float value)
{
Parameter* param = GetParameterByKey(parameter);
if (dynamic_cast<FloatParameter*>(param))
{
FloatParameter* paramFloat = dynamic_cast<FloatParameter*>(param);
paramFloat->SetDefaultValue(value);
paramFloat->SetValue(value);
}
}
void Application::SetParameterString(std::string parameter, std::string value)
{
Parameter* param = GetParameterByKey(parameter);
......
......@@ -183,6 +183,28 @@ public:
*/
void SetParameterFloat(std::string parameter, float value);
/* Set an default integer value,must used in the
* DoCreateParameters when setting a value by default
* for the parameter
*
* Can be called for types :
* \li ParameterType_Int
* \li ParameterType_Float
* \li ParameterType_Radius
* \li ParameterType_Choice
*/
void SetDefaultParameterInt(std::string parameter, int value);
/* Set a default floating value, must used in the
* DoCreateParameters when setting a value by default
* for the parameter
*
* Can be called for types :
* \li ParameterType_Float
*/
void SetDefaultParameterFloat(std::string parameter, float value);
/* Set a string value
*
* Can be called for types :
......
......@@ -76,5 +76,14 @@ void QtWidgetParameterBase::SetActivationState( bool value )
m_Param->SetChecked(value);
m_Param->SetActive(value);
}
// Slot connected to the signal emitted by the Reset Button
void QtWidgetParameterBase::Reset( )
{
m_Param->Reset();
m_Param->SetUserValue(false);
m_Param->SetAutomaticValue(false);
this->UpdateGUI();
}
}
}
......@@ -42,6 +42,7 @@ public:
public slots:
void UpdateGUI();
virtual void SetActivationState( bool value );
void Reset();
protected slots:
void ParameterChanged(const QString& key);
......
......@@ -63,7 +63,7 @@ void QtWidgetParameterGroup::DoCreateWidget()
if (paramAsGroup == 0 && paramAsChoice == 0)
{
// Label (col 0)
// Label (col 1)
QWidget* label = new QtWidgetParameterLabel( param );
gridLayout->addWidget(label, i, 1);
......@@ -71,7 +71,7 @@ void QtWidgetParameterGroup::DoCreateWidget()
QtWidgetParameterBase* specificWidget = QtWidgetParameterFactory::CreateQtWidget( param, GetModel() );
gridLayout->addWidget(specificWidget, i, 2 );
// CheckBox (col 1)
// CheckBox (col 0)
QCheckBox * checkBox = new QCheckBox;
connect( checkBox, SIGNAL(clicked(bool)), specificWidget, SLOT(SetActivationState(bool)));
connect( checkBox, SIGNAL(clicked(bool)), GetModel(), SLOT(NotifyUpdate()) );
......@@ -91,8 +91,24 @@ void QtWidgetParameterGroup::DoCreateWidget()
checkBox->setEnabled(true);
specificWidget->setEnabled(false);
}
gridLayout->addWidget(checkBox, i, 0);
// Reset Button
// Make sense only for NumericalParameter
if (dynamic_cast<IntParameter*>(param)
|| dynamic_cast<FloatParameter*>(param)
|| dynamic_cast<RadiusParameter*>(param) )
{
QPushButton* resetButton = new QPushButton;
resetButton->setText("Reset");
resetButton->setToolTip("Reset the value of this parameter");
gridLayout->addWidget(resetButton, i, 3);
// Slots to connect to the reset button
connect( resetButton, SIGNAL(clicked()), specificWidget, SLOT(Reset()) );
connect( resetButton, SIGNAL(clicked()), GetModel(), SLOT(NotifyUpdate()) );
}
m_WidgetList.push_back(specificWidget);
}
else
......
......@@ -20,6 +20,8 @@
#include <QtGui>
#include "otbWrapperParameterGroup.h"
#include "otbWrapperNumericalParameter.h"
#include "otbWrapperRadiusParameter.h"
#include "otbWrapperQtWidgetParameterBase.h"
namespace otb
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment