Skip to content

Commit

Permalink
Re #5366. Disable 'Add' option in combobox for histogram listeners.
Browse files Browse the repository at this point in the history
And select 'Replace' by default instead. Marginally smarter way of doing
it than the previous way.
  • Loading branch information
RussellTaylor committed Feb 6, 2013
1 parent 5905e6d commit e00f644
Showing 1 changed file with 25 additions and 8 deletions.
33 changes: 25 additions & 8 deletions Code/Mantid/MantidQt/CustomDialogs/src/StartLiveDataDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,25 +298,42 @@ void StartLiveDataDialog::changePostProcessingAlgorithm()

//------------------------------------------------------------------------------
/** Slot called when picking a different instrument.
* @param inst :: The instrument name.
* Disables the 'Add' option if the listener is going to pass back histograms.
* @param inst :: The instrument name.
*/
void StartLiveDataDialog::setDefaultAccumulationMethod(const QString& inst)
{
if ( inst.isEmpty() ) return;
try
{
// Make sure 'Add' is enabled ahead of the check (the check may throw)
int addIndex = ui.cmbAccumulationMethod->findText("Add");
ui.cmbAccumulationMethod->setItemData(addIndex, QVariant(Qt::ItemIsSelectable | Qt::ItemIsEnabled), Qt::UserRole - 1);

Mantid::Kernel::InstrumentInfo instrument = Mantid::Kernel::ConfigService::Instance().getInstrument(inst.toStdString());
std::string listenerName = instrument.liveListener();
if ( listenerName.find("Histo") != std::string::npos )
{
ui.cmbAccumulationMethod->setCurrentText("Replace");
}
else
// Two checks here. The first is just based on the name of the listener, the second is in
// principle more robust, but will throw if the listener can't connect (not that you'll
// get very far in that case anyway).
if ( listenerName.find("Histo") != std::string::npos
|| !Mantid::API::LiveListenerFactory::Instance().create(instrument.name())->buffersEvents() )
{
ui.cmbAccumulationMethod->setCurrentText("Add");
// If 'Add' is currently selected, select 'Replace' instead
if ( ui.cmbAccumulationMethod->currentIndex() == addIndex )
{
ui.cmbAccumulationMethod->setCurrentText("Replace");
}
// Disable the 'Add' option in the combobox. It just wouldn't make sense.
ui.cmbAccumulationMethod->setItemData(addIndex, false, Qt::UserRole - 1);
}
}
catch( ... )
// If an exception is thrown, just swallow it and do nothing
// getInstrument can throw, particularly while we allow listener names to be passed in directly
catch( Mantid::Kernel::Exception::NotFoundError& )
{
}
// The LiveListenerFactory create() method will throw if it can't connect
catch( std::runtime_error& )
{
}
}
Expand Down

0 comments on commit e00f644

Please sign in to comment.