From 5dd8eba85d105d248220dc41ba727e84eeacec9c Mon Sep 17 00:00:00 2001
From: Elliot Oram <Elliot.Oram@stfc.ac.uk>
Date: Fri, 4 Sep 2015 12:06:06 +0100
Subject: [PATCH] Added new tab to IndirectCorrections and clang format

Refs #13110
---
 .../Indirect/ContainerSubtraction.h           |   5 +
 .../Indirect/IndirectCorrections.h            | 146 ++++-----
 .../Indirect/IndirectCorrections.ui           |   5 +
 .../src/Indirect/ContainerSubtraction.cpp     |  10 +
 .../src/Indirect/IndirectCorrections.cpp      | 290 +++++++++---------
 5 files changed, 241 insertions(+), 215 deletions(-)

diff --git a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/ContainerSubtraction.h b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/ContainerSubtraction.h
index 04844fadb62..c572e7162d9 100644
--- a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/ContainerSubtraction.h
+++ b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/ContainerSubtraction.h
@@ -15,6 +15,11 @@ public:
 private slots:
 
 private:
+  virtual void setup();
+  virtual void run();
+  virtual bool validate();
+  virtual void loadSettings(const QSettings &settings);
+
   Ui::ContainerSubtraction m_uiForm;
 };
 
diff --git a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/IndirectCorrections.h b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/IndirectCorrections.h
index 7834f259b4e..9601b1cf601 100644
--- a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/IndirectCorrections.h
+++ b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/IndirectCorrections.h
@@ -15,79 +15,79 @@ class DoubleEditorFactory;
 class QtCheckBoxFactory;
 class QtStringPropertyManager;
 
-namespace MantidQt
-{
-namespace CustomInterfaces
-{
-  // The assumption is made elsewhere that the ordering of these enums matches the ordering of the
-  // tabs as they appear in the interface itself.
-  enum CorrectionTabChoice
-  {
-    CALC_CORR,
-    APPLY_CORR,
-    ABSORPTION_CORRECTIONS
-  };
-
-  // Forward Declaration
-  class CorrectionsTab;
-
-  /**
-   * The IndirectCorrections class is the main class that handles the interface and controls
-   * its tabs.
-   *
-   * Is a friend to the CorrectionsTab class.
-   */
-  class IndirectCorrections : public MantidQt::API::UserSubWindow
-  {
-    Q_OBJECT
-
-    /// Allow CorrectionsTab to have access.
-    friend class CorrectionsTab;
-
-  public:
-    /// The name of the interface as registered into the factory
-    static std::string name() { return "Corrections"; }
-    // This interface's categories.
-    static QString categoryInfo() { return "Indirect"; }
-    /// Default Constructor
-    IndirectCorrections(QWidget *parent = 0);
-
-  private:
-    /// Initialize the layout
-    virtual void initLayout();
-    /// Initialize Python-dependent sections
-    virtual void initLocalPython();
-    /// Load the settings of the interface (and child tabs).
-    void loadSettings();
-
-    /// Called upon a close event.
-    virtual void closeEvent(QCloseEvent*);
-    /// handle POCO event
-    void handleDirectoryChange(Mantid::Kernel::ConfigValChangeNotification_ptr pNf);
-
-  private slots:
-    /// Called when the user clicks the Py button
-    void exportTabPython();
-    /// Called when the Run button is pressed.  Runs current tab.
-    void run();
-    /// Opens a directory dialog.
-    void openDirectoryDialog();
-    /// Opens the Mantid Wiki web page of the current tab.
-    void help();
-    /// Slot showing a message box to the user
-    void showMessageBox(const QString& message);
-
-  private:
-    /// UI form containing all Qt elements.
-    Ui::IndirectCorrections m_uiForm;
-
-    /// Change Observer for ConfigService (monitors user directories)
-    Poco::NObserver<IndirectCorrections, Mantid::Kernel::ConfigValChangeNotification> m_changeObserver;
-
-    /// Map of unsigned int (TabChoice enum values) to tabs.
-    std::map<unsigned int, CorrectionsTab*> m_tabs;
-
-  };
+namespace MantidQt {
+namespace CustomInterfaces {
+// The assumption is made elsewhere that the ordering of these enums matches the
+// ordering of the
+// tabs as they appear in the interface itself.
+enum CorrectionTabChoice {
+  CALC_CORR,
+  APPLY_CORR,
+  ABSORPTION_CORRECTIONS,
+  CONTAINER_SUBTRACTION
+};
+
+// Forward Declaration
+class CorrectionsTab;
+
+/**
+ * The IndirectCorrections class is the main class that handles the interface
+ * and controls
+ * its tabs.
+ *
+ * Is a friend to the CorrectionsTab class.
+ */
+class IndirectCorrections : public MantidQt::API::UserSubWindow {
+  Q_OBJECT
+
+  /// Allow CorrectionsTab to have access.
+  friend class CorrectionsTab;
+
+public:
+  /// The name of the interface as registered into the factory
+  static std::string name() { return "Corrections"; }
+  // This interface's categories.
+  static QString categoryInfo() { return "Indirect"; }
+  /// Default Constructor
+  IndirectCorrections(QWidget *parent = 0);
+
+private:
+  /// Initialize the layout
+  virtual void initLayout();
+  /// Initialize Python-dependent sections
+  virtual void initLocalPython();
+  /// Load the settings of the interface (and child tabs).
+  void loadSettings();
+
+  /// Called upon a close event.
+  virtual void closeEvent(QCloseEvent *);
+  /// handle POCO event
+  void
+  handleDirectoryChange(Mantid::Kernel::ConfigValChangeNotification_ptr pNf);
+
+private slots:
+  /// Called when the user clicks the Py button
+  void exportTabPython();
+  /// Called when the Run button is pressed.  Runs current tab.
+  void run();
+  /// Opens a directory dialog.
+  void openDirectoryDialog();
+  /// Opens the Mantid Wiki web page of the current tab.
+  void help();
+  /// Slot showing a message box to the user
+  void showMessageBox(const QString &message);
+
+private:
+  /// UI form containing all Qt elements.
+  Ui::IndirectCorrections m_uiForm;
+
+  /// Change Observer for ConfigService (monitors user directories)
+  Poco::NObserver<IndirectCorrections,
+                  Mantid::Kernel::ConfigValChangeNotification> m_changeObserver;
+
+  /// Map of unsigned int (TabChoice enum values) to tabs.
+  std::map<unsigned int, CorrectionsTab *> m_tabs;
+};
 } // namespace CustomInterfaces
 } // namespace MantidQt
 
diff --git a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/IndirectCorrections.ui b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/IndirectCorrections.ui
index 362ff31f3e9..5260a6d54fb 100644
--- a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/IndirectCorrections.ui
+++ b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/IndirectCorrections.ui
@@ -41,6 +41,11 @@
         <string>Absorption</string>
        </attribute>
       </widget>
+      <widget class="QWidget" name="tabContainerSubtraction">
+        <attribute name="title">
+          <string>Container Subtraction</string>
+        </attribute>
+      </widget>
      </widget>
     </item>
     <item>
diff --git a/Code/Mantid/MantidQt/CustomInterfaces/src/Indirect/ContainerSubtraction.cpp b/Code/Mantid/MantidQt/CustomInterfaces/src/Indirect/ContainerSubtraction.cpp
index 970696e16eb..57c5b6501c7 100644
--- a/Code/Mantid/MantidQt/CustomInterfaces/src/Indirect/ContainerSubtraction.cpp
+++ b/Code/Mantid/MantidQt/CustomInterfaces/src/Indirect/ContainerSubtraction.cpp
@@ -12,5 +12,15 @@ ContainerSubtraction::ContainerSubtraction(QWidget *parent)
     : CorrectionsTab(parent) {
   m_uiForm.setupUi(parent);
 }
+
+void ContainerSubtraction::setup() {}
+void ContainerSubtraction::run() {}
+bool ContainerSubtraction::validate() { return false; }
+
+void ContainerSubtraction::loadSettings(const QSettings &settings) {
+  m_uiForm.dsCorrections->readSettings(settings.group());
+  m_uiForm.dsContainer->readSettings(settings.group());
+  m_uiForm.dsSample->readSettings(settings.group());
+}
 }
 }
\ No newline at end of file
diff --git a/Code/Mantid/MantidQt/CustomInterfaces/src/Indirect/IndirectCorrections.cpp b/Code/Mantid/MantidQt/CustomInterfaces/src/Indirect/IndirectCorrections.cpp
index ab988fcc813..62d4f61a4aa 100644
--- a/Code/Mantid/MantidQt/CustomInterfaces/src/Indirect/IndirectCorrections.cpp
+++ b/Code/Mantid/MantidQt/CustomInterfaces/src/Indirect/IndirectCorrections.cpp
@@ -6,6 +6,7 @@
 #include "MantidQtCustomInterfaces/Indirect/CalculatePaalmanPings.h"
 #include "MantidQtCustomInterfaces/Indirect/ApplyPaalmanPings.h"
 #include "MantidQtCustomInterfaces/Indirect/AbsorptionCorrections.h"
+#include "MantidQtCustomInterfaces/Indirect/ContainerSubtraction.h"
 
 #include "MantidQtAPI/HelpWindow.h"
 #include "MantidQtAPI/ManageUserDirectories.h"
@@ -15,151 +16,156 @@
 #include <QDesktopServices>
 #include <QUrl>
 
-namespace MantidQt
-{
-namespace CustomInterfaces
-{
-  // Add this class to the list of specialised dialogs in this namespace
-  DECLARE_SUBWINDOW(IndirectCorrections)
-
-  /**
-   * Constructor.
-   *
-   * @param parent :: the parent QWidget.
-   */
-  IndirectCorrections::IndirectCorrections(QWidget *parent) :
-    UserSubWindow(parent),
-    m_changeObserver(*this, &IndirectCorrections::handleDirectoryChange)
-  {
-    m_uiForm.setupUi(this);
-
-    // Allows us to get a handle on a tab using an enum, for example "m_tabs[ELWIN]".
-    // All tabs MUST appear here to be shown in interface.
-    // We make the assumption that each map key corresponds to the order in which the tabs appear.
-    m_tabs.insert(std::make_pair(CALC_CORR,  new CalculatePaalmanPings(m_uiForm.twTabs->widget(CALC_CORR))));
-    m_tabs.insert(std::make_pair(APPLY_CORR, new ApplyPaalmanPings(m_uiForm.twTabs->widget(APPLY_CORR))));
-    m_tabs.insert(std::make_pair(ABSORPTION_CORRECTIONS, new AbsorptionCorrections(m_uiForm.twTabs->widget(ABSORPTION_CORRECTIONS))));
-  }
-
-  /**
-   * @param :: the detected close event
-   */
-  void IndirectCorrections::closeEvent(QCloseEvent*)
-  {
-    Mantid::Kernel::ConfigService::Instance().removeObserver(m_changeObserver);
-  }
-
-  /**
-   * Handles a change in directory.
-   *
-   * @param pNf :: notification
-   */
-  void IndirectCorrections::handleDirectoryChange(Mantid::Kernel::ConfigValChangeNotification_ptr pNf)
-  {
-    std::string key = pNf->key();
-
-    if ( key == "defaultsave.directory" )
-      loadSettings();
-  }
-
-  /**
-   * Initialised the layout of the interface.  MUST be called.
-   */
-  void IndirectCorrections::initLayout()
-  {
-    // Connect Poco Notification Observer
-    Mantid::Kernel::ConfigService::Instance().addObserver(m_changeObserver);
-
-    // Set up all tabs
-    for(auto tab = m_tabs.begin(); tab != m_tabs.end(); ++tab)
-    {
-      tab->second->setupTab();
-      connect(tab->second, SIGNAL(runAsPythonScript(const QString&, bool)), this, SIGNAL(runAsPythonScript(const QString&, bool)));
-      connect(tab->second, SIGNAL(showMessageBox(const QString&)), this, SLOT(showMessageBox(const QString&)));
-    }
-
-    connect(m_uiForm.pbPythonExport, SIGNAL(clicked()), this, SLOT(exportTabPython()));
-    connect(m_uiForm.pbHelp, SIGNAL(clicked()), this, SLOT(help()));
-    connect(m_uiForm.pbRun, SIGNAL(clicked()), this, SLOT(run()));
-    connect(m_uiForm.pbManageDirs, SIGNAL(clicked()), this, SLOT(openDirectoryDialog()));
-  }
-
-  /**
-   * Allow Python to be called locally.
-   */
-  void IndirectCorrections::initLocalPython()
-  {
-    QString pyInput = "from mantid.simpleapi import *";
-    QString pyOutput = runPythonCode(pyInput).trimmed();
+namespace MantidQt {
+namespace CustomInterfaces {
+// Add this class to the list of specialised dialogs in this namespace
+DECLARE_SUBWINDOW(IndirectCorrections)
+
+/**
+ * Constructor.
+ *
+ * @param parent :: the parent QWidget.
+ */
+IndirectCorrections::IndirectCorrections(QWidget *parent)
+    : UserSubWindow(parent),
+      m_changeObserver(*this, &IndirectCorrections::handleDirectoryChange) {
+  m_uiForm.setupUi(this);
+
+  // Allows us to get a handle on a tab using an enum, for example
+  // "m_tabs[ELWIN]".
+  // All tabs MUST appear here to be shown in interface.
+  // We make the assumption that each map key corresponds to the order in which
+  // the tabs appear.
+  m_tabs.insert(std::make_pair(
+      CALC_CORR,
+      new CalculatePaalmanPings(m_uiForm.twTabs->widget(CALC_CORR))));
+  m_tabs.insert(std::make_pair(
+      APPLY_CORR, new ApplyPaalmanPings(m_uiForm.twTabs->widget(APPLY_CORR))));
+  m_tabs.insert(std::make_pair(
+      ABSORPTION_CORRECTIONS, new AbsorptionCorrections(m_uiForm.twTabs->widget(
+                                  ABSORPTION_CORRECTIONS))));
+  m_tabs.insert(std::make_pair(CONTAINER_SUBTRACTION,
+                               new ContainerSubtraction(m_uiForm.twTabs->widget(
+                                   CONTAINER_SUBTRACTION))));
+}
+
+/**
+ * @param :: the detected close event
+ */
+void IndirectCorrections::closeEvent(QCloseEvent *) {
+  Mantid::Kernel::ConfigService::Instance().removeObserver(m_changeObserver);
+}
+
+/**
+ * Handles a change in directory.
+ *
+ * @param pNf :: notification
+ */
+void IndirectCorrections::handleDirectoryChange(
+    Mantid::Kernel::ConfigValChangeNotification_ptr pNf) {
+  std::string key = pNf->key();
+
+  if (key == "defaultsave.directory")
     loadSettings();
+}
+
+/**
+ * Initialised the layout of the interface.  MUST be called.
+ */
+void IndirectCorrections::initLayout() {
+  // Connect Poco Notification Observer
+  Mantid::Kernel::ConfigService::Instance().addObserver(m_changeObserver);
+
+  // Set up all tabs
+  for (auto tab = m_tabs.begin(); tab != m_tabs.end(); ++tab) {
+    tab->second->setupTab();
+    connect(tab->second, SIGNAL(runAsPythonScript(const QString &, bool)), this,
+            SIGNAL(runAsPythonScript(const QString &, bool)));
+    connect(tab->second, SIGNAL(showMessageBox(const QString &)), this,
+            SLOT(showMessageBox(const QString &)));
   }
 
-  /**
-   * Load the settings saved for this interface.
-   */
-  void IndirectCorrections::loadSettings()
-  {
-    QSettings settings;
-    QString settingsGroup = "CustomInterfaces/IndirectAnalysis/";
-    QString saveDir = QString::fromStdString(Mantid::Kernel::ConfigService::Instance().getString("defaultsave.directory"));
-
-    settings.beginGroup(settingsGroup + "ProcessedFiles");
-    settings.setValue("last_directory", saveDir);
-
-    // Load each tab's settings.
-    auto tab = m_tabs.begin();
-    for( ; tab != m_tabs.end(); ++tab )
-      tab->second->loadTabSettings(settings);
-
-    settings.endGroup();
-  }
-
-  /**
-   * Private slot, called when the Run button is pressed.  Runs current tab.
-   */
-  void IndirectCorrections::run()
-  {
-    const unsigned int currentTab = m_uiForm.twTabs->currentIndex();
-    m_tabs[currentTab]->runTab();
-  }
-
-  /**
-   * Opens a directory dialog.
-   */
-  void IndirectCorrections::openDirectoryDialog()
-  {
-    MantidQt::API::ManageUserDirectories *ad = new MantidQt::API::ManageUserDirectories(this);
-    ad->show();
-    ad->setFocus();
-  }
-
-  /**
-   * Opens the Mantid Wiki web page of the current tab.
-   */
-  void IndirectCorrections::help()
-  {
-    MantidQt::API::HelpWindow::showCustomInterface(NULL, QString("Indirect_Corrections"));
-  }
-
-  /**
-   * Handles exporting a Python script for the current tab.
-   */
-  void IndirectCorrections::exportTabPython()
-  {
-    unsigned int currentTab = m_uiForm.twTabs->currentIndex();
-    m_tabs[currentTab]->exportPythonScript();
-  }
-
-  /**
-   * Slot to wrap the protected showInformationBox method defined
-   * in UserSubWindow and provide access to composed tabs.
-   *
-   * @param message The message to display in the message box
-   */
-  void IndirectCorrections::showMessageBox(const QString& message)
-  {
-    showInformationBox(message);
-  }
+  connect(m_uiForm.pbPythonExport, SIGNAL(clicked()), this,
+          SLOT(exportTabPython()));
+  connect(m_uiForm.pbHelp, SIGNAL(clicked()), this, SLOT(help()));
+  connect(m_uiForm.pbRun, SIGNAL(clicked()), this, SLOT(run()));
+  connect(m_uiForm.pbManageDirs, SIGNAL(clicked()), this,
+          SLOT(openDirectoryDialog()));
+}
+
+/**
+ * Allow Python to be called locally.
+ */
+void IndirectCorrections::initLocalPython() {
+  QString pyInput = "from mantid.simpleapi import *";
+  QString pyOutput = runPythonCode(pyInput).trimmed();
+  loadSettings();
+}
+
+/**
+ * Load the settings saved for this interface.
+ */
+void IndirectCorrections::loadSettings() {
+  QSettings settings;
+  QString settingsGroup = "CustomInterfaces/IndirectAnalysis/";
+  QString saveDir = QString::fromStdString(
+      Mantid::Kernel::ConfigService::Instance().getString(
+          "defaultsave.directory"));
+
+  settings.beginGroup(settingsGroup + "ProcessedFiles");
+  settings.setValue("last_directory", saveDir);
+
+  // Load each tab's settings.
+  auto tab = m_tabs.begin();
+  for (; tab != m_tabs.end(); ++tab)
+    tab->second->loadTabSettings(settings);
+
+  settings.endGroup();
+}
+
+/**
+ * Private slot, called when the Run button is pressed.  Runs current tab.
+ */
+void IndirectCorrections::run() {
+  const unsigned int currentTab = m_uiForm.twTabs->currentIndex();
+  m_tabs[currentTab]->runTab();
+}
+
+/**
+ * Opens a directory dialog.
+ */
+void IndirectCorrections::openDirectoryDialog() {
+  MantidQt::API::ManageUserDirectories *ad =
+      new MantidQt::API::ManageUserDirectories(this);
+  ad->show();
+  ad->setFocus();
+}
+
+/**
+ * Opens the Mantid Wiki web page of the current tab.
+ */
+void IndirectCorrections::help() {
+  MantidQt::API::HelpWindow::showCustomInterface(
+      NULL, QString("Indirect_Corrections"));
+}
+
+/**
+ * Handles exporting a Python script for the current tab.
+ */
+void IndirectCorrections::exportTabPython() {
+  unsigned int currentTab = m_uiForm.twTabs->currentIndex();
+  m_tabs[currentTab]->exportPythonScript();
+}
+
+/**
+ * Slot to wrap the protected showInformationBox method defined
+ * in UserSubWindow and provide access to composed tabs.
+ *
+ * @param message The message to display in the message box
+ */
+void IndirectCorrections::showMessageBox(const QString &message) {
+  showInformationBox(message);
+}
 
 } // namespace CustomInterfaces
 } // namespace MantidQt
-- 
GitLab