Skip to content

Commit

Permalink
Re #8911. Handle cases of missing data.
Browse files Browse the repository at this point in the history
  • Loading branch information
mantid-roman committed Oct 31, 2014
1 parent 817d3de commit 206edc1
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 9 deletions.
Expand Up @@ -79,6 +79,8 @@ class MultiDatasetFit: public API::UserSubWindow
double getLocalParameterValue(const QString& parName, int i) const;
/// Display info about the plot.
void showPlotInfo();
/// Check that the data sets in the table are valid
void checkDataSets();

signals:
void dataTableUpdated();
Expand Down Expand Up @@ -110,6 +112,7 @@ private slots:
bool eventFilter(QObject *widget, QEvent *evn);
void showFunctionBrowserInfo();
void showTableInfo();
void removeDataSets(std::vector<int>& rows);

/// The form generated by Qt Designer
Ui::MultiDatasetFit m_uiForm;
Expand Down
70 changes: 61 additions & 9 deletions Code/Mantid/MantidQt/CustomInterfaces/src/MultiDatasetFit.cpp
Expand Up @@ -393,6 +393,7 @@ void PlotController::plotDataSet(int index)
if ( index < 0 || index >= m_table->rowCount() )
{
clear();
owner()->checkDataSets();
m_plot->replot();
return;
}
Expand All @@ -409,8 +410,18 @@ void PlotController::plotDataSet(int index)
{
outputWorkspaceName += QString("_%1").arg(index);
}
auto value = boost::make_shared<DatasetPlotData>( wsName, wsIndex, outputWorkspaceName );
m_plotData.insert(index, value );
try
{
auto value = boost::make_shared<DatasetPlotData>( wsName, wsIndex, outputWorkspaceName );
m_plotData.insert(index, value );
}
catch(...)
{
clear();
owner()->checkDataSets();
m_plot->replot();
return;
}
}

// hide the previously shown data
Expand Down Expand Up @@ -697,12 +708,7 @@ void MultiDatasetFit::removeSelectedSpectra()
rows.push_back( row );
}
}
std::sort( rows.begin(), rows.end() );
for(auto row = rows.rbegin(); row != rows.rend(); ++row)
{
m_uiForm.dataTable->removeRow( *row );
}
emit dataTableUpdated();
removeDataSets( rows );
}

/**
Expand Down Expand Up @@ -1064,7 +1070,53 @@ void MultiDatasetFit::showPlotInfo()

void MultiDatasetFit::showTableInfo()
{
showInfo("Select spectra by selecting rows. For multiple selection use Shift or Ctrl keys.");
if ( getNumberOfSpectra() > 0 )
{
showInfo("Select spectra by selecting rows. For multiple selection use Shift or Ctrl keys.");
}
else
{
showInfo("Add some data sets. Click \"Add Workspace\" button.");
}
}

/**
* Check that the data sets in the table are valid and remove invalid ones.
*/
void MultiDatasetFit::checkDataSets()
{
std::vector<int> rows;
int nrows = getNumberOfSpectra();
auto& ADS = Mantid::API::AnalysisDataService::Instance();
for( int row = 0; row < nrows; ++row)
{
auto wsName = getWorkspaceName( row );
auto i = getWorkspaceIndex( row );
if ( !ADS.doesExist( wsName ) )
{
rows.push_back( row );
continue;
}
auto ws = ADS.retrieveWS<Mantid::API::MatrixWorkspace>( wsName );
if ( !ws || i >= ws->getNumberHistograms() )
{
rows.push_back( row );
continue;
}
}

removeDataSets( rows );
}

void MultiDatasetFit::removeDataSets( std::vector<int>& rows )
{
if ( rows.empty() ) return;
std::sort( rows.begin(), rows.end() );
for(auto row = rows.rbegin(); row != rows.rend(); ++row)
{
m_uiForm.dataTable->removeRow( *row );
}
emit dataTableUpdated();
}

/*==========================================================================================*/
Expand Down

0 comments on commit 206edc1

Please sign in to comment.