diff --git a/qt/widgets/common/inc/MantidQtWidgets/Common/BasicFitOptionsBrowser.h b/qt/widgets/common/inc/MantidQtWidgets/Common/BasicFitOptionsBrowser.h index fceaaad5a4f920d459413eabe5608c1619d6c4ba..16a613e153b5fc5d5e0e06df00b4a164f3a2a69e 100644 --- a/qt/widgets/common/inc/MantidQtWidgets/Common/BasicFitOptionsBrowser.h +++ b/qt/widgets/common/inc/MantidQtWidgets/Common/BasicFitOptionsBrowser.h @@ -31,6 +31,11 @@ namespace MantidWidgets { class EXPORT_OPT_MANTIDQT_COMMON BasicFitOptionsBrowser : public QWidget { Q_OBJECT + using PropertySetter = void (BasicFitOptionsBrowser::*)(QtProperty *, + std::string const &); + using PropertyGetter = + std::string (BasicFitOptionsBrowser::*)(QtProperty *) const; + public: BasicFitOptionsBrowser(QWidget *parent = nullptr); ~BasicFitOptionsBrowser(); @@ -38,12 +43,11 @@ public: void setFittingMode(FittingMode fittingMode); FittingMode getFittingMode() const; - void setProperty(const QString &name, const QString &value); - QString getProperty(const QString &name) const; + void setProperty(std::string const &name, std::string const &value); + std::string getProperty(std::string const &name) const; signals: - void changedToSequentialFitting(); - void changedToSimultaneousFitting(); + void fittingModeChanged(FittingMode fittingMode); private slots: void enumChanged(QtProperty *prop); @@ -57,19 +61,16 @@ private: void createCostFunctionProperty(); void createEvaluationTypeProperty(); - void emitFittingModeChanged(); + void addProperty(std::string const &name, QtProperty *prop, + PropertyGetter getter, PropertySetter setter); - void addProperty(const QString &name, QtProperty *prop, - QString (BasicFitOptionsBrowser::*getter)(QtProperty *) - const, - void (BasicFitOptionsBrowser::*setter)(QtProperty *, - const QString &)); + void setIntProperty(QtProperty *prop, std::string const &value); + std::string getIntProperty(QtProperty *prop) const; - void setIntProperty(QtProperty *prop, QString const &value); - QString getIntProperty(QtProperty *prop) const; + void setStringEnumProperty(QtProperty *prop, std::string const &value); + std::string getStringEnumProperty(QtProperty *prop) const; - void setStringEnumProperty(QtProperty *prop, QString const &value); - QString getStringEnumProperty(QtProperty *prop) const; + QtProperty *getQtPropertyFor(std::string const &name) const; /// Property managers QtIntPropertyManager *m_intManager; @@ -85,16 +86,12 @@ private: /// Qt property browser which displays properties QtTreePropertyBrowser *m_browser; - using SetterType = void (BasicFitOptionsBrowser::*)(QtProperty *, - const QString &); - using GetterType = QString (BasicFitOptionsBrowser::*)(QtProperty *) const; - /// Maps algorithm property name to the QtProperty - QMap<QString, QtProperty *> m_propertyNameMap; - /// Store for the properties setter methods - QMap<QtProperty *, SetterType> m_setters; - /// Store for the properties getter methods - QMap<QtProperty *, GetterType> m_getters; + QMap<std::string, QtProperty *> m_propertyNameMap; + /// Store for the property setter methods + QMap<QtProperty *, PropertySetter> m_setters; + /// Store for the property getter methods + QMap<QtProperty *, PropertyGetter> m_getters; }; } // namespace MantidWidgets diff --git a/qt/widgets/common/inc/MantidQtWidgets/Common/FitScriptGeneratorView.h b/qt/widgets/common/inc/MantidQtWidgets/Common/FitScriptGeneratorView.h index 09d3ce6f1a972a18809a48fb3eff73865e8a07aa..cf76f426eb7796813b4bfd4474eeb5e8d2ec9141 100644 --- a/qt/widgets/common/inc/MantidQtWidgets/Common/FitScriptGeneratorView.h +++ b/qt/widgets/common/inc/MantidQtWidgets/Common/FitScriptGeneratorView.h @@ -122,8 +122,7 @@ private slots: void onGlobalParametersChanged(QStringList const &globalParameters); void onCopyFunctionToClipboard(); void onFunctionHelpRequested(); - void onChangeToSequentialFitting(); - void onChangeToSimultaneousFitting(); + void onFittingModeChanged(FittingMode fittingMode); private: void connectUiSignals(); diff --git a/qt/widgets/common/src/BasicFitOptionsBrowser.cpp b/qt/widgets/common/src/BasicFitOptionsBrowser.cpp index c02f6da551c98f89c63aa3d3d0a04ab98da76a40..4e49e65e93b85e90de026aaf6233996008fe38a0 100644 --- a/qt/widgets/common/src/BasicFitOptionsBrowser.cpp +++ b/qt/widgets/common/src/BasicFitOptionsBrowser.cpp @@ -26,6 +26,7 @@ static QStringList FITTING_MODES = {"Sequential", "Simultaneous"}; QStringList convertToQStringList(std::vector<std::string> const &vec) { QStringList list; + list.reserve(static_cast<int>(vec.size())); std::transform( vec.cbegin(), vec.cend(), std::back_inserter(list), [](std::string const &str) { return QString::fromStdString(str); }); @@ -94,7 +95,7 @@ void BasicFitOptionsBrowser::createFittingModeProperty() { m_enumManager->setEnumNames(m_fittingMode, FITTING_MODES); m_browser->addProperty(m_fittingMode); - emitFittingModeChanged(); + emit fittingModeChanged(getFittingMode()); } void BasicFitOptionsBrowser::createMaxIterationsProperty() { @@ -104,7 +105,7 @@ void BasicFitOptionsBrowser::createMaxIterationsProperty() { m_intManager->setMinimum(m_maxIterations, 0); m_browser->addProperty(m_maxIterations); - addProperty("MaxIterations", m_maxIterations, + addProperty("Max Iterations", m_maxIterations, &BasicFitOptionsBrowser::getIntProperty, &BasicFitOptionsBrowser::setIntProperty); } @@ -127,7 +128,7 @@ void BasicFitOptionsBrowser::createCostFunctionProperty() { m_enumManager->setEnumNames(m_costFunction, costFunctions()); m_browser->addProperty(m_costFunction); - addProperty("CostFunction", m_costFunction, + addProperty("Cost Function", m_costFunction, &BasicFitOptionsBrowser::getStringEnumProperty, &BasicFitOptionsBrowser::setStringEnumProperty); } @@ -138,81 +139,70 @@ void BasicFitOptionsBrowser::createEvaluationTypeProperty() { m_enumManager->setEnumNames(m_evaluationType, EVALUATION_TYPES); m_browser->addProperty(m_evaluationType); - addProperty("EvaluationType", m_evaluationType, + addProperty("Evaluation Type", m_evaluationType, &BasicFitOptionsBrowser::getStringEnumProperty, &BasicFitOptionsBrowser::setStringEnumProperty); } -void BasicFitOptionsBrowser::addProperty( - const QString &name, QtProperty *prop, - QString (BasicFitOptionsBrowser::*getter)(QtProperty *) const, - void (BasicFitOptionsBrowser::*setter)(QtProperty *, const QString &)) { +void BasicFitOptionsBrowser::addProperty(std::string const &name, + QtProperty *prop, + PropertyGetter getter, + PropertySetter setter) { m_propertyNameMap[name] = prop; m_getters[prop] = getter; m_setters[prop] = setter; } -void BasicFitOptionsBrowser::setProperty(const QString &name, - const QString &value) { - if (!m_propertyNameMap.contains(name)) { - throw std::runtime_error("Property " + name.toStdString() + - " isn't supported by the browser."); - } - auto prop = m_propertyNameMap[name]; - auto f = m_setters[prop]; +void BasicFitOptionsBrowser::setProperty(std::string const &name, + std::string const &value) { + auto const prop = getQtPropertyFor(name); + auto const f = m_setters[prop]; (this->*f)(prop, value); } -QString BasicFitOptionsBrowser::getProperty(const QString &name) const { +std::string BasicFitOptionsBrowser::getProperty(std::string const &name) const { + auto const prop = getQtPropertyFor(name); + auto const f = m_getters[prop]; + return (this->*f)(prop); +} + +QtProperty * +BasicFitOptionsBrowser::getQtPropertyFor(std::string const &name) const { if (!m_propertyNameMap.contains(name)) { - throw std::runtime_error("Property " + name.toStdString() + + throw std::runtime_error("Property " + name + " isn't supported by the browser."); } - auto prop = m_propertyNameMap[name]; - auto f = m_getters[prop]; - return (this->*f)(prop); + return m_propertyNameMap[name]; } void BasicFitOptionsBrowser::enumChanged(QtProperty *prop) { if (prop == m_fittingMode) { - emitFittingModeChanged(); - } -} - -void BasicFitOptionsBrowser::emitFittingModeChanged() { - switch (getFittingMode()) { - case FittingMode::SEQUENTIAL: - emit changedToSequentialFitting(); - return; - case FittingMode::SIMULTANEOUS: - emit changedToSimultaneousFitting(); - return; - default: - throw std::runtime_error( - "Fitting mode must be SEQUENTIAL or SIMULTANEOUS."); + emit fittingModeChanged(getFittingMode()); } } void BasicFitOptionsBrowser::setIntProperty(QtProperty *prop, - QString const &value) { - m_intManager->setValue(prop, value.toInt()); + std::string const &value) { + m_intManager->setValue(prop, QString::fromStdString(value).toInt()); } -QString BasicFitOptionsBrowser::getIntProperty(QtProperty *prop) const { - return QString::number(m_intManager->value(prop)); +std::string BasicFitOptionsBrowser::getIntProperty(QtProperty *prop) const { + return QString::number(m_intManager->value(prop)).toStdString(); } void BasicFitOptionsBrowser::setStringEnumProperty(QtProperty *prop, - QString const &value) { - auto const i = m_enumManager->enumNames(prop).indexOf(value); + std::string const &value) { + auto const i = + m_enumManager->enumNames(prop).indexOf(QString::fromStdString(value)); if (i >= 0) m_enumManager->setValue(prop, i); } -QString BasicFitOptionsBrowser::getStringEnumProperty(QtProperty *prop) const { +std::string +BasicFitOptionsBrowser::getStringEnumProperty(QtProperty *prop) const { auto const i = m_enumManager->value(prop); if (i >= 0) - return m_enumManager->enumNames(prop)[i]; + return m_enumManager->enumNames(prop)[i].toStdString(); return ""; } @@ -231,8 +221,7 @@ void BasicFitOptionsBrowser::setFittingMode(FittingMode fittingMode) { } FittingMode BasicFitOptionsBrowser::getFittingMode() const { - auto const value = m_enumManager->value(m_fittingMode); - return static_cast<FittingMode>(value); + return static_cast<FittingMode>(m_enumManager->value(m_fittingMode)); } } // namespace MantidWidgets diff --git a/qt/widgets/common/src/FitScriptGeneratorView.cpp b/qt/widgets/common/src/FitScriptGeneratorView.cpp index e2ddbe5f89cb29b022c08816e00d46d879ce6fce..28cb87eb5f6f49a459468a40b8ca43a75de0a568 100644 --- a/qt/widgets/common/src/FitScriptGeneratorView.cpp +++ b/qt/widgets/common/src/FitScriptGeneratorView.cpp @@ -123,10 +123,8 @@ void FitScriptGeneratorView::connectUiSignals() { connect(m_functionTreeView.get(), SIGNAL(functionHelpRequest()), this, SLOT(onFunctionHelpRequested())); - connect(m_fitOptionsBrowser.get(), SIGNAL(changedToSequentialFitting()), this, - SLOT(onChangeToSequentialFitting())); - connect(m_fitOptionsBrowser.get(), SIGNAL(changedToSimultaneousFitting()), - this, SLOT(onChangeToSimultaneousFitting())); + connect(m_fitOptionsBrowser.get(), SIGNAL(fittingModeChanged(FittingMode)), + this, SLOT(onFittingModeChanged(FittingMode))); /// Disconnected because it causes a crash when selecting a table row while /// editing a parameters value. This is because selecting a different row will @@ -140,7 +138,8 @@ void FitScriptGeneratorView::connectUiSignals() { void FitScriptGeneratorView::setFitBrowserOptions( QMap<QString, QString> const &fitOptions) { for (auto it = fitOptions.constBegin(); it != fitOptions.constEnd(); ++it) - m_fitOptionsBrowser->setProperty(it.key(), it.value()); + m_fitOptionsBrowser->setProperty(it.key().toStdString(), + it.value().toStdString()); } void FitScriptGeneratorView::setFittingMode(FittingMode fittingMode) { @@ -238,14 +237,8 @@ void FitScriptGeneratorView::onFunctionHelpRequested() { QString::fromStdString(function->name())); } -void FitScriptGeneratorView::onChangeToSequentialFitting() { - m_presenter->notifyPresenter(ViewEvent::FittingModeChanged, - FittingMode::SEQUENTIAL); -} - -void FitScriptGeneratorView::onChangeToSimultaneousFitting() { - m_presenter->notifyPresenter(ViewEvent::FittingModeChanged, - FittingMode::SIMULTANEOUS); +void FitScriptGeneratorView::onFittingModeChanged(FittingMode fittingMode) { + m_presenter->notifyPresenter(ViewEvent::FittingModeChanged, fittingMode); } std::string FitScriptGeneratorView::workspaceName(FitDomainIndex index) const { diff --git a/scripts/Muon/GUI/Common/fitting_tab_widget/fitting_tab_presenter.py b/scripts/Muon/GUI/Common/fitting_tab_widget/fitting_tab_presenter.py index ab28f69d7e8a8b84e9a2f1afbff996b51292b166..00517b30e7458749cd0a1e0e13553686fc260d98 100644 --- a/scripts/Muon/GUI/Common/fitting_tab_widget/fitting_tab_presenter.py +++ b/scripts/Muon/GUI/Common/fitting_tab_widget/fitting_tab_presenter.py @@ -106,7 +106,7 @@ class FittingTabPresenter(object): def handle_fit_generator_clicked(self): fitting_mode = FittingMode.SIMULTANEOUS if self.view.is_simul_fit else FittingMode.SEQUENTIAL - fit_options = {"Minimizer": self.view.minimizer, "EvaluationType": self.view.evaluation_type} + fit_options = {"Minimizer": self.view.minimizer, "Evaluation Type": self.view.evaluation_type} self.fsg_model = FitScriptGeneratorModel() self.fsg_view = FitScriptGeneratorView(None, fitting_mode, fit_options)