Mantid
Loading...
Searching...
No Matches
IFunctionView.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
7#pragma once
8
9#include "DllOption.h"
10
11#include "MantidAPI/IFunction.h"
12
13#include <QString>
14#include <QWidget>
15#include <boost/optional.hpp>
16#include <type_traits>
17
18namespace MantidQt {
19namespace MantidWidgets {
20
21using namespace Mantid::API;
22
27 Q_OBJECT
28public:
29 IFunctionView(QWidget *parent = nullptr) : QWidget(parent) {}
30 virtual ~IFunctionView() = default;
31 virtual void clear() = 0;
32 virtual void setFunction(IFunction_sptr fun) = 0;
33 virtual bool hasFunction() const = 0;
35 virtual void setParameter(const QString &paramName, double value) = 0;
36 virtual void setParameterError(const QString &paramName, double error) = 0;
37 virtual double getParameter(const QString &paramName) const = 0;
38 virtual IFunction::Attribute getAttribute(const QString &attrName) const = 0;
39 virtual void setErrorsEnabled(bool enabled) = 0;
40 virtual void clearErrors() = 0;
41 virtual boost::optional<QString> currentFunctionIndex() const = 0;
42 virtual void setParameterTie(const QString &paramName, const QString &tie) = 0;
43 virtual void setParameterConstraint(const QString &paramName, const QString &constraint) = 0;
44 virtual void setGlobalParameters(const QStringList &) = 0;
45 virtual void showFunctionHelp(const QString &) const = 0;
46 // Set the value of an attribute based on the template type
47 template <typename T> void setAttributeValue(const QString &attributeName, T &value) {
48 if constexpr (std::is_same_v<T, double>) {
49 setDoubleAttribute(attributeName, value);
50 } else if constexpr (std::is_same_v<T, int>) {
51 setIntAttribute(attributeName, value);
52 } else if constexpr (std::is_same_v<T, QString>) {
53 setStringAttribute(attributeName, value);
54 } else if constexpr (std::is_same_v<T, bool>) {
55 setBooleanAttribute(attributeName, value);
56 } else if constexpr (std::is_same_v<T, std::vector<double>>) {
57 setVectorAttribute(attributeName, value);
58 }
59 }
60
61protected:
62 virtual void setDoubleAttribute(const QString &paramName, double value) = 0;
63 virtual void setIntAttribute(const QString &paramName, int value) = 0;
64 virtual void setStringAttribute(const QString &paramName, std::string &value) = 0;
65 virtual void setBooleanAttribute(const QString &paramName, bool value) = 0;
66 virtual void setVectorAttribute(const QString &paramName, std::vector<double> &val) = 0;
67
68signals:
70 void functionReplaced(const QString &funStr);
72 void functionAdded(const QString &funStr);
74 void functionRemoved(const QString &functionIndex);
76 void functionRemovedString(const QString &funStr);
80 void parameterChanged(const QString &paramName);
82 void attributePropertyChanged(const QString &attrName);
84 void localParameterButtonClicked(const QString &parName);
86 void parameterTieChanged(const QString &parName, const QString &tie);
88 void parameterConstraintAdded(const QString &functionIndex, const QString &constraint);
90 void parameterConstraintRemoved(const QString &paramName);
96 void globalsChanged(const QStringList &);
97};
98
99} // namespace MantidWidgets
100} // namespace MantidQt
#define EXPORT_OPT_MANTIDQT_COMMON
Definition: DllOption.h:15
double value
The value of the point.
Definition: FitMW.cpp:51
double error
Definition: IndexPeaks.cpp:133
The interface to a function view.
Definition: IFunctionView.h:26
void globalsChanged(const QStringList &)
User changed the list of global parameters.
virtual double getParameter(const QString &paramName) const =0
void attributePropertyChanged(const QString &attrName)
Function attribute gets changed.
virtual void setIntAttribute(const QString &paramName, int value)=0
void parameterConstraintAdded(const QString &functionIndex, const QString &constraint)
User sets a constraint.
IFunctionView(QWidget *parent=nullptr)
Definition: IFunctionView.h:29
virtual void setFunction(IFunction_sptr fun)=0
virtual void setVectorAttribute(const QString &paramName, std::vector< double > &val)=0
void localParameterButtonClicked(const QString &parName)
In multi-dataset context a button value editor was clicked.
virtual void setStringAttribute(const QString &paramName, std::string &value)=0
virtual void setParameterError(const QString &paramName, double error)=0
virtual void setBooleanAttribute(const QString &paramName, bool value)=0
void parameterTieChanged(const QString &parName, const QString &tie)
User sets a tie.
virtual void setParameterTie(const QString &paramName, const QString &tie)=0
void copyToClipboardRequest()
User requested copy function to clipboard.
void functionRemoved(const QString &functionIndex)
User removes a function.
virtual void setDoubleAttribute(const QString &paramName, double value)=0
virtual boost::optional< QString > currentFunctionIndex() const =0
virtual void setParameter(const QString &paramName, double value)=0
void functionHelpRequest()
User requested function help.
void parameterConstraintRemoved(const QString &paramName)
User removes a constraint.
void functionAdded(const QString &funStr)
User adds a function.
void functionReplaced(const QString &funStr)
User replaces the whole function (eg, by pasting it from clipboard)
void functionRemovedString(const QString &funStr)
User removes a function.
virtual bool hasFunction() const =0
void setAttributeValue(const QString &attributeName, T &value)
Definition: IFunctionView.h:47
virtual IFunction_sptr getSelectedFunction()=0
virtual void setErrorsEnabled(bool enabled)=0
virtual void showFunctionHelp(const QString &) const =0
void currentFunctionChanged()
User selects a different (sub)function (or one of it's sub-properties)
virtual void setGlobalParameters(const QStringList &)=0
virtual void setParameterConstraint(const QString &paramName, const QString &constraint)=0
void parameterChanged(const QString &paramName)
Function parameter gets changed.
virtual IFunction::Attribute getAttribute(const QString &attrName) const =0
Attribute is a non-fitting parameter.
Definition: IFunction.h:282
The AlgorithmProgressDialogPresenter keeps track of the running algorithms and displays a progress ba...
std::shared_ptr< IFunction > IFunction_sptr
shared pointer to the function base class
Definition: IFunction.h:732