From 09c3fa536bab1254dec71b23ac4b48b439eb653f Mon Sep 17 00:00:00 2001 From: Applin Date: Thu, 23 May 2024 13:58:11 +0100 Subject: [PATCH] Store presenters as unique ptrs in Data Manipulation Interface class --- .../Indirect/Reduction/DataReduction.h | 1 + .../DataManipulationInterface.cpp | 66 ++----------------- .../Manipulation/DataManipulationInterface.h | 32 ++++----- 3 files changed, 17 insertions(+), 82 deletions(-) diff --git a/qt/scientific_interfaces/Indirect/Reduction/DataReduction.h b/qt/scientific_interfaces/Indirect/Reduction/DataReduction.h index 5216631fba30..04603f8fa418 100644 --- a/qt/scientific_interfaces/Indirect/Reduction/DataReduction.h +++ b/qt/scientific_interfaces/Indirect/Reduction/DataReduction.h @@ -14,6 +14,7 @@ #include "MantidGeometry/IComponent.h" #include "MantidQtWidgets/Common/QtAlgorithmRunner.h" +#include #include #include diff --git a/qt/scientific_interfaces/Inelastic/Manipulation/DataManipulationInterface.cpp b/qt/scientific_interfaces/Inelastic/Manipulation/DataManipulationInterface.cpp index 2c09249784fa..a92426149ecb 100644 --- a/qt/scientific_interfaces/Inelastic/Manipulation/DataManipulationInterface.cpp +++ b/qt/scientific_interfaces/Inelastic/Manipulation/DataManipulationInterface.cpp @@ -4,9 +4,6 @@ // NScD Oak Ridge National Laboratory, European Spallation Source, // Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS // SPDX - License - Identifier: GPL - 3.0 + -//---------------------- -// Includes -//---------------------- #include "DataManipulationInterface.h" #include "Common/Settings.h" @@ -39,7 +36,7 @@ DECLARE_SUBWINDOW(DataManipulationInterface) DataManipulationInterface::DataManipulationInterface(QWidget *parent) : InelasticInterface(parent) {} -DataManipulationInterface::~DataManipulationInterface() {} +DataManipulationInterface::~DataManipulationInterface() = default; std::string DataManipulationInterface::documentationPage() const { return "Inelastic Data Manipulation"; } @@ -47,8 +44,8 @@ std::string DataManipulationInterface::documentationPage() const { return "Inela * Called when the user clicks the Python export button. */ void DataManipulationInterface::exportTabPython() { - QString tabName = m_uiForm.twIDRTabs->tabText(m_uiForm.twIDRTabs->currentIndex()); - m_tabs[tabName].second->exportPythonScript(); + auto const tabName = m_uiForm.twIDRTabs->tabText(m_uiForm.twIDRTabs->currentIndex()).toStdString(); + m_presenters[tabName]->exportPythonScript(); } /** @@ -73,27 +70,15 @@ void DataManipulationInterface::initLayout() { // Connect the "Manage User Directories" Button connect(m_uiForm.pbManageDirectories, SIGNAL(clicked()), this, SLOT(manageUserDirectories())); - auto const &facility = Mantid::Kernel::ConfigService::Instance().getFacility(); - filterUiForFacility(QString::fromStdString(facility.name())); - InelasticInterface::initLayout(); } void DataManipulationInterface::applySettings(std::map const &settings) { - for (auto tab = m_tabs.begin(); tab != m_tabs.end(); ++tab) { + for (auto tab = m_presenters.begin(); tab != m_presenters.end(); ++tab) { tab->second->filterInputData(settings.at("RestrictInput").toBool()); } } -/** - * This function is ran after initLayout(), and runPythonCode is unavailable - * before this function - * has run (because of the setup of the base class). For this reason, "setup" - * functions that require - * Python scripts are located here. - */ -void DataManipulationInterface::initLocalPython() {} - /** * Gets a parameter from an instrument component as a string. * @@ -134,47 +119,4 @@ void DataManipulationInterface::instrumentLoadingDone(bool error) { } } -/** - * Remove the Poco observer on the config service when the interfaces is closed. - * - * @param close Close event (unused) - */ -void DataManipulationInterface::closeEvent(QCloseEvent *close) { UNUSED_ARG(close); } - -/** - * Filters the displayed tabs based on the current facility. - * - * @param facility Name of facility - */ -void DataManipulationInterface::filterUiForFacility(const QString &facility) { - g_log.information() << "Facility selected: " << facility.toStdString() << '\n'; - QStringList enabledTabs; - QStringList disabledInstruments; - - // These tabs work at any facility (always at end of tabs) - enabledTabs << "Symmetrise" - << "S(Q, w)" - << "Moments" - << "Elwin" - << "Iqt"; - - // First remove all tabs - while (m_uiForm.twIDRTabs->count() > 0) { - QString tabName = m_uiForm.twIDRTabs->tabText(0); - - // Remove the tab - m_uiForm.twIDRTabs->removeTab(0); - - g_log.debug() << "Removing tab " << tabName.toStdString() << '\n'; - } - - // Add the required tabs - for (auto &enabledTab : enabledTabs) { - // Add the tab - m_uiForm.twIDRTabs->addTab(m_tabs[enabledTab].first, enabledTab); - - g_log.debug() << "Adding tab " << enabledTab.toStdString() << '\n'; - } -} - } // namespace MantidQt::CustomInterfaces diff --git a/qt/scientific_interfaces/Inelastic/Manipulation/DataManipulationInterface.h b/qt/scientific_interfaces/Inelastic/Manipulation/DataManipulationInterface.h index 7a535e351a81..1a7996c7e39e 100644 --- a/qt/scientific_interfaces/Inelastic/Manipulation/DataManipulationInterface.h +++ b/qt/scientific_interfaces/Inelastic/Manipulation/DataManipulationInterface.h @@ -12,6 +12,9 @@ #include "MantidGeometry/IComponent.h" +#include +#include + #include #include @@ -43,16 +46,12 @@ class DataManipulationInterface : public InelasticInterface { /// Initialize the layout void initLayout() override; - /// Run Python-based initialisation commands - void initLocalPython() override; signals: /// Emitted when the instrument setup is changed void newInstrumentConfiguration(); private slots: - /// Shows/hides tabs based on facility - void filterUiForFacility(const QString &facility); /// Exports the current tab algorithms as a Python script void exportTabPython(); @@ -67,9 +66,6 @@ private slots: QString getInstrumentParameterFrom(const Mantid::Geometry::IComponent_const_sptr &comp, const std::string ¶m); - /// Set and show an instrument-specific widget - void closeEvent(QCloseEvent *close) override; - /** * Adds an MVP tab to the cache of tabs that can be shown. * @@ -79,7 +75,7 @@ private slots: * @param name Name to be displayed on tab */ - template void addMVPTab(const QString &name) { + template void addMVPTab(const std::string &name) { QWidget *tabWidget = new QWidget(m_uiForm.twIDRTabs); QVBoxLayout *tabLayout = new QVBoxLayout(tabWidget); tabWidget->setLayout(tabLayout); @@ -89,33 +85,29 @@ private slots: tabScrollArea->setWidgetResizable(true); QWidget *tabContent = new QWidget(tabScrollArea); - tabContent->setObjectName("tab" + QString(name).remove(QRegExp("[ ,()]"))); + tabContent->setObjectName("tab" + QString::fromStdString(name).remove(QRegExp("[ ,()]"))); tabScrollArea->setWidget(tabContent); tabScrollArea->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); - DataManipulation *tabIDRContent = new TabPresenter(tabContent, new TabView(tabContent)); + auto presenter = std::make_unique(tabContent, new TabView(tabContent)); - tabIDRContent->setupTab(); + presenter->setupTab(); tabContent->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); - connect(tabIDRContent, SIGNAL(showMessageBox(const QString &)), this, SLOT(showMessageBox(const QString &))); + connect(presenter.get(), SIGNAL(showMessageBox(const QString &)), this, SLOT(showMessageBox(const QString &))); - // Add to the cache - m_tabs[name] = qMakePair(tabWidget, tabIDRContent); + m_presenters[name] = std::move(presenter); // Add all tabs to UI initially - m_uiForm.twIDRTabs->addTab(tabWidget, name); + m_uiForm.twIDRTabs->addTab(tabWidget, QString::fromStdString(name)); } friend class DataManipulation; /// The .ui form generated by Qt Designer Ui::DataManipulationInterface m_uiForm; - // All indirect tabs - QMap> m_tabs; - - QString m_dataDir; ///< default data search directory - QString m_saveDir; ///< default data save directory + /// A map to hold the presenter corresponding to each tab + std::unordered_map> m_presenters; }; } // namespace CustomInterfaces