Skip to content

Commit

Permalink
Update icon visibility on dialog after error when hitting run.
Browse files Browse the repository at this point in the history
The updateIconVisibility method now accepts an error string so that
it doesn't have to recheck the property if it already has the error
string from it.
Refs #9756
  • Loading branch information
martyngigg committed Jun 30, 2014
1 parent ff472ed commit 224abc0
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 26 deletions.
2 changes: 1 addition & 1 deletion Code/Mantid/MantidQt/API/inc/MantidQtAPI/PropertyWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ namespace API

public slots:
/// Update which icons should be shown.
void updateIconVisibility();
void updateIconVisibility(const QString & error = "");
/// Deal with the "replace workspace" button being clicked.
void replaceWSButtonClicked();
/// Emits a signal that the value of the property was changed.
Expand Down
11 changes: 3 additions & 8 deletions Code/Mantid/MantidQt/API/src/GenericDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,18 +167,13 @@ void GenericDialog::accept()
else
{
// Highlight the validators that are in error (combined from them + whole algorithm)
auto itr = m_algoPropertiesWidget->m_propWidgets.begin();
for(; itr != m_algoPropertiesWidget->m_propWidgets.end(); itr++ )
{
if (m_errors.contains(itr.key()))
itr.value()->setError( m_errors[itr.key()] );
}
// If got there, there were errors
for(auto it = m_errors.begin(); it != m_errors.end(); it++)
m_algoPropertiesWidget->m_propWidgets[it.key()]->updateIconVisibility(it.value());

QMessageBox::critical(this, "",
"One or more properties are invalid. The invalid properties are\n"
"marked with a *, hold your mouse over the * for more information." );
}
}



36 changes: 20 additions & 16 deletions Code/Mantid/MantidQt/API/src/PropertyWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,29 +298,33 @@ namespace API

/**
* Update which icons should be shown.
* @param error An optional error string. If empty the property is revalidated by calling prop->setValue and
* the error is pulled from here
*/
void PropertyWidget::updateIconVisibility()
void PropertyWidget::updateIconVisibility(const QString &error)
{
// Show "*" icon if the value is invalid for this property.
QString value = this->getValue().trimmed();
// Use the default if empty
if( value.isEmpty() )
value = QString::fromStdString(m_prop->getDefault());

std::string error("");
try
QString userError(error);
if(userError.isEmpty())
{
error = m_prop->setValue(value.toStdString());
// Show "*" icon if the value is invalid for this property.
QString value = this->getValue().trimmed();
// Use the default if empty
if( value.isEmpty() )
value = QString::fromStdString(m_prop->getDefault());

try
{
userError = QString::fromStdString(m_prop->setValue(value.toStdString()));
}
catch(std::exception & err_details)
{
userError = QString::fromAscii(err_details.what());
}
}
catch(std::exception & err_details)
{
error = err_details.what();
}
this->setError(QString::fromStdString(error).trimmed());
this->setError(userError.trimmed());

m_icons[INVALID]->setVisible(!m_error.isEmpty());
m_icons[INVALID]->setToolTip(m_error);

// Show "!" icon if a workspace would be overwritten.
if( m_isOutputWsProp )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,5 +103,5 @@ void SmoothNeighboursDialog::accept()

// If got there, there were errors
for(auto it = m_errors.begin(); it != m_errors.end(); it++)
m_propertiesWidget->m_propWidgets[it.key()]->setError(it.value());
m_propertiesWidget->m_propWidgets[it.key()]->updateIconVisibility(it.value());
}

0 comments on commit 224abc0

Please sign in to comment.