From d53a678d87d1ff6242ba356919c2a4d6dff4a6e7 Mon Sep 17 00:00:00 2001
From: Shahroz Ahmed <shahroz.ahmed@stfc.ac.uk>
Date: Wed, 21 Oct 2015 15:02:22 +0100
Subject: [PATCH] sets enginx default instr when different default instr
 selected

Refs #14006
---
 .../EnggDiffractionViewQtGUI.h                |  8 +++--
 .../EnggDiffractionViewQtGUI.cpp              | 29 ++++++++++---------
 2 files changed, 21 insertions(+), 16 deletions(-)

diff --git a/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/EnggDiffraction/EnggDiffractionViewQtGUI.h b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/EnggDiffraction/EnggDiffractionViewQtGUI.h
index a3304d2c7a3..4a0988c8d53 100644
--- a/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/EnggDiffraction/EnggDiffractionViewQtGUI.h
+++ b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/EnggDiffraction/EnggDiffractionViewQtGUI.h
@@ -198,8 +198,11 @@ private:
   /// instrument selected (ENGIN-X, etc.)
   std::string m_currentInst;
 
-  /// the instrument selection has changed (slot)
-  void userSelectInstrument();
+  /// User select instrument
+  void userSelectInstrument(const QString &prefix);
+
+  /// setting the instrument prefix ahead of the run number
+  void setPrefix(std::string prefix);
 
   // plot data representation type selected
   int static m_currentType;
@@ -227,7 +230,6 @@ private:
 
   /// presenter as in the model-view-presenter
   boost::scoped_ptr<IEnggDiffractionPresenter> m_presenter;
-
 };
 
 } // namespace CustomInterfaces
diff --git a/MantidQt/CustomInterfaces/src/EnggDiffraction/EnggDiffractionViewQtGUI.cpp b/MantidQt/CustomInterfaces/src/EnggDiffraction/EnggDiffractionViewQtGUI.cpp
index a092a39fdc3..2c4b2b77bbb 100644
--- a/MantidQt/CustomInterfaces/src/EnggDiffraction/EnggDiffractionViewQtGUI.cpp
+++ b/MantidQt/CustomInterfaces/src/EnggDiffraction/EnggDiffractionViewQtGUI.cpp
@@ -76,6 +76,9 @@ void EnggDiffractionViewQtGUI::initLayout() {
   m_uiTabSettings.setupUi(wSettings);
   m_ui.tabMain->addTab(wSettings, QString("Settings"));
 
+  QComboBox *inst = m_ui.comboBox_instrument;
+  m_currentInst = inst->currentText().toStdString();
+  setPrefix(m_currentInst);
   readSettings();
 
   // basic UI setup, connect signals, etc.
@@ -177,12 +180,6 @@ void EnggDiffractionViewQtGUI::doSetupGeneralWidgets() {
   // change instrument
   connect(m_ui.comboBox_instrument, SIGNAL(currentIndexChanged(int)), this,
           SLOT(instrumentChanged(int)));
-
-  // signal/slot connections to respond to changes in instrument selection combo
-  // boxes
-  connect(m_ui.comboBox_instrument, SIGNAL(instrumentChanged(int)), this,
-          SLOT(userSelectInstrument()));
-
   connect(m_ui.pushButton_help, SIGNAL(released()), this, SLOT(openHelpWin()));
   // note connection to the parent window, otherwise an empty frame window
   // may remain open and visible after this close
@@ -744,15 +741,21 @@ void EnggDiffractionViewQtGUI::instrumentChanged(int /*idx*/) {
   m_presenter->notify(IEnggDiffractionPresenter::InstrumentChange);
 }
 
-void EnggDiffractionViewQtGUI::userSelectInstrument() {
+void EnggDiffractionViewQtGUI::userSelectInstrument(const QString &prefix) {
   // Set file browsing to current instrument
-  auto prefix = QString::fromStdString(m_currentInst);
-  m_uiTabFocus.lineEdit_run_num->setInstrumentOverride(prefix);
-  m_uiTabFocus.lineEdit_texture_run_num->setInstrumentOverride(prefix);
-  m_uiTabFocus.lineEdit_cropped_run_num->setInstrumentOverride(prefix);
+  setPrefix(prefix.toStdString());
+}
+
+void EnggDiffractionViewQtGUI::setPrefix(std::string prefix) {
+  QString prefixInput = QString::fromStdString(prefix);
+  // focus tab
+  m_uiTabFocus.lineEdit_run_num->setInstrumentOverride(prefixInput);
+  m_uiTabFocus.lineEdit_texture_run_num->setInstrumentOverride(prefixInput);
+  m_uiTabFocus.lineEdit_cropped_run_num->setInstrumentOverride(prefixInput);
 
-  m_uiTabCalib.lineEdit_new_ceria_num->setInstrumentOverride(prefix);
-  m_uiTabCalib.lineEdit_new_vanadium_num->setInstrumentOverride(prefix);
+  // calibration tab
+  m_uiTabCalib.lineEdit_new_ceria_num->setInstrumentOverride(prefixInput);
+  m_uiTabCalib.lineEdit_new_vanadium_num->setInstrumentOverride(prefixInput);
 }
 
 void EnggDiffractionViewQtGUI::closeEvent(QCloseEvent *event) {
-- 
GitLab