Skip to content
Snippets Groups Projects
Commit 3d9e0a5b authored by Guillaume Pasero's avatar Guillaume Pasero
Browse files

BUG: Mantis-1098: fix interactive edition of InputProcessXMLParameter in QtWidget

parent 861ed67a
No related branches found
No related tags found
No related merge requests found
...@@ -43,19 +43,10 @@ public: ...@@ -43,19 +43,10 @@ public:
// Get Value // Get Value
//TODO otbGetObjectMemberMacro(StringParam, Value , std::string); //TODO otbGetObjectMemberMacro(StringParam, Value , std::string);
void SetFileName(std::string value) bool SetFileName(std::string value);
{
this->SetValue(value);
}
// Set Value // Set Value
virtual void SetValue(const std::string value) virtual void SetValue(const std::string value);
{
itkDebugMacro("setting member m_FileName to " << value);
this->m_FileName = value;
SetActive(true);
this->Modified();
}
ImagePixelType GetPixelTypeFromString(std::string pixTypeAsString); ImagePixelType GetPixelTypeFromString(std::string pixTypeAsString);
......
...@@ -807,7 +807,8 @@ void Application::SetParameterString(std::string parameter, std::string value) ...@@ -807,7 +807,8 @@ void Application::SetParameterString(std::string parameter, std::string value)
else if (dynamic_cast<InputProcessXMLParameter*>(param)) else if (dynamic_cast<InputProcessXMLParameter*>(param))
{ {
InputProcessXMLParameter* paramDown = dynamic_cast<InputProcessXMLParameter*>(param); InputProcessXMLParameter* paramDown = dynamic_cast<InputProcessXMLParameter*>(param);
paramDown->SetValue(value); if ( !paramDown->SetFileName(value) )
otbAppLogCRITICAL( <<"Invalid XML parameter filename " << value <<".");
} }
} }
......
...@@ -41,6 +41,34 @@ InputProcessXMLParameter::~InputProcessXMLParameter() ...@@ -41,6 +41,34 @@ InputProcessXMLParameter::~InputProcessXMLParameter()
} }
bool
InputProcessXMLParameter::SetFileName(std::string value)
{
// Check if the filename is not empty
if(!value.empty())
{
// Check that the right extension is given : expected .xml
if (itksys::SystemTools::GetFilenameLastExtension(value) == ".xml")
{
if (itksys::SystemTools::FileExists(value.c_str(),true))
{
this->SetValue(value);
return true;
}
}
}
return false;
}
void
InputProcessXMLParameter::SetValue(const std::string value)
{
itkDebugMacro("setting member m_FileName to " << value);
this->m_FileName = value;
SetActive(true);
this->Modified();
}
ImagePixelType ImagePixelType
InputProcessXMLParameter::GetPixelTypeFromString(std::string strType) InputProcessXMLParameter::GetPixelTypeFromString(std::string strType)
{ {
...@@ -134,18 +162,6 @@ InputProcessXMLParameter::GetChildNodeTextOf(TiXmlElement *parentElement, std::s ...@@ -134,18 +162,6 @@ InputProcessXMLParameter::GetChildNodeTextOf(TiXmlElement *parentElement, std::s
int int
InputProcessXMLParameter::Read(Application::Pointer this_) InputProcessXMLParameter::Read(Application::Pointer this_)
{ {
// Check if the filename is not empty
if(m_FileName.empty())
itkExceptionMacro(<<"The XML input FileName is empty, please set the filename via the method SetFileName");
// Check that the right extension is given : expected .xml
if (itksys::SystemTools::GetFilenameLastExtension(m_FileName) != ".xml")
{
itkExceptionMacro(<<itksys::SystemTools::GetFilenameLastExtension(m_FileName) << " " << m_FileName << " "
<<" is a wrong Extension FileName : Expected .xml");
}
// Open the xml file // Open the xml file
TiXmlDocument doc; TiXmlDocument doc;
......
...@@ -34,10 +34,13 @@ QtWidgetInputProcessXMLParameter::~QtWidgetInputProcessXMLParameter() ...@@ -34,10 +34,13 @@ QtWidgetInputProcessXMLParameter::~QtWidgetInputProcessXMLParameter()
void QtWidgetInputProcessXMLParameter::DoUpdateGUI() void QtWidgetInputProcessXMLParameter::DoUpdateGUI()
{ {
// Update the lineEdit if (m_XMLParam->HasUserValue())
QString text( m_XMLParam->GetFileName() ); {
if (text != m_Input->text()) // Update the lineEdit
m_Input->setText(text); QString text( m_XMLParam->GetFileName() );
if (text != m_Input->text())
m_Input->setText(text);
}
} }
void QtWidgetInputProcessXMLParameter::DoCreateWidget() void QtWidgetInputProcessXMLParameter::DoCreateWidget()
...@@ -85,15 +88,13 @@ void QtWidgetInputProcessXMLParameter::SelectFile() ...@@ -85,15 +88,13 @@ void QtWidgetInputProcessXMLParameter::SelectFile()
void QtWidgetInputProcessXMLParameter::SetFileName(const QString& value) void QtWidgetInputProcessXMLParameter::SetFileName(const QString& value)
{ {
// load xml file name // load xml file name
m_XMLParam->SetValue(value.toAscii().constData()); if (m_XMLParam->SetFileName(value.toAscii().constData()))
{
// notify of value change // notify of value change
QString key( m_XMLParam->GetKey() ); QString key( m_XMLParam->GetKey() );
emit ParameterChanged(key);
emit ParameterChanged(key); GetModel()->UpdateAllWidgets();
}
GetModel()->UpdateAllWidgets();
} }
} }
......
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