Commit 28c3abb8 authored by Guillaume Pasero's avatar Guillaume Pasero

BUG: Mantis-1182: avoid crash with ComplexInputImageParameter (same behavior...

BUG: Mantis-1182: avoid crash with ComplexInputImageParameter (same behavior as InputImageParameter)
parent 9ddebfcb
......@@ -43,7 +43,7 @@ public:
virtual ~QtWidgetComplexInputImageParameter();
protected slots:
void SetFileName( const QString& value );
bool SetFileName( const QString& value );
void SelectFile();
private:
......
......@@ -34,14 +34,18 @@ QtWidgetComplexInputImageParameter::~QtWidgetComplexInputImageParameter()
void QtWidgetComplexInputImageParameter::DoUpdateGUI()
{
QString text(
QFile::decodeName(
m_ComplexInputImageParam->GetFileName().c_str()
)
);
if (text != m_Input->text())
m_Input->setText(text);
//update lineedit if HasUserValue flag is set(from xml)
if(m_ComplexInputImageParam->HasUserValue())
{
QString text(
QFile::decodeName(
m_ComplexInputImageParam->GetFileName().c_str()
)
);
if (text != m_Input->text())
m_Input->setText(text);
}
}
void QtWidgetComplexInputImageParameter::DoCreateWidget()
......@@ -75,24 +79,48 @@ void QtWidgetComplexInputImageParameter::SelectFile()
fileDialog.setFileMode(QFileDialog::ExistingFile);
fileDialog.setNameFilter("Raster files (*)");
if (fileDialog.exec())
assert( m_Input!=NULL );
if( !m_Input->text().isEmpty() )
{
this->SetFileName( fileDialog.selectedFiles().at(0) );
QFileInfo finfo( m_Input->text() );
fileDialog.setDirectory(
finfo.isDir()
? finfo.absoluteFilePath()
: finfo.absoluteDir()
);
}
m_Input->setText(fileDialog.selectedFiles().at(0));
if (fileDialog.exec())
{
if ( this->SetFileName( fileDialog.selectedFiles().at(0) ) == true )
m_Input->setText(fileDialog.selectedFiles().at(0));
else
{
std::ostringstream oss;
oss << "The given file "
<< QFile::encodeName( fileDialog.selectedFiles().at( 0 ) ).constData()
<< " is not valid.";
this->GetModel()->SendLogWARNING( oss.str() );
}
}
}
void QtWidgetComplexInputImageParameter::SetFileName(const QString& value)
bool QtWidgetComplexInputImageParameter::SetFileName(const QString& value)
{
bool res = false;
// save value
m_ComplexInputImageParam->SetFromFileName(
QFile::encodeName( value ).constData()
);
if( m_ComplexInputImageParam->SetFromFileName(
QFile::encodeName( value ).constData()) == true)
{
res = true;
// notify of value change
QString key( m_ComplexInputImageParam->GetKey() );
emit ParameterChanged(key);
}
// notify of value change
QString key( m_ComplexInputImageParam->GetKey() );
emit ParameterChanged(key);
return res;
}
}
......
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