Mantid
Loading...
Searching...
No Matches
PropertyHandler.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#include "MantidAPI/IFunction.h"
11
12/* Forward declarations */
13namespace Mantid {
14namespace API {
15class IPeakFunction;
16class CompositeFunction;
17} // namespace API
18} // namespace Mantid
19
20// class FunctionCurve;
21// class PlotCurve;
22// class Graph;
23class QtBrowserItem;
24class QtProperty;
25
26/* Qt includes */
27#include <QList>
28#include <QMap>
29#include <QObject>
30#include <QString>
31
32namespace MantidQt {
33namespace MantidWidgets {
34class FitPropertyBrowser;
35
40 Q_OBJECT
41public:
42 // Constructor
43 PropertyHandler(const Mantid::API::IFunction_sptr &fun, std::shared_ptr<Mantid::API::CompositeFunction> parent,
44 FitPropertyBrowser *browser, QtBrowserItem *item = nullptr);
45
47 ~PropertyHandler() override;
48
50 void init() override;
51
52 PropertyHandler *addFunction(const std::string &fnName);
53 // Removes handled function from its parent function and
54 // properties from the browser
55 void removeFunction();
56
57 void renameChildren(const Mantid::API::CompositeFunction &cf);
58
61 QString functionName() const;
62
63 QString functionPrefix() const;
64
65 // Return composite function
66 std::shared_ptr<Mantid::API::CompositeFunction> cfun() const { return m_cf; }
67 // Return peak function
68 std::shared_ptr<Mantid::API::IPeakFunction> pfun() const { return m_pf; }
69 // Return IFunction
70 std::shared_ptr<Mantid::API::IFunction> ifun() const { return m_fun; }
71 // Return the browser item
72 QtBrowserItem *item() const { return m_item; }
73 // Return the parent handler
74 PropertyHandler *parentHandler() const;
75 // Return the child's handler
76 PropertyHandler *getHandler(std::size_t i) const;
81 std::shared_ptr<const Mantid::API::CompositeFunction> findCompositeFunction(QtBrowserItem *item) const;
86 std::shared_ptr<const Mantid::API::IFunction> findFunction(QtBrowserItem *item) const;
87
88 PropertyHandler *findHandler(const Mantid::API::IFunction *fun);
90 PropertyHandler *findHandler(QtProperty *prop);
91
97 bool setParameter(QtProperty *prop);
98
99 // Check if it is a parameter property
100 bool isParameter(QtProperty *prop);
101
103 bool setAttribute(QtProperty *prop, bool resetProperties = true);
104
106 void setAttribute(QString const &attName, Mantid::API::IFunction::Attribute const &attValue);
107
109 template <typename AttributeType> void setAttribute(QString const &attName, AttributeType const &attValue);
110
112 void setAttribute(const QString &attName, const QString &attValue);
113
115 void setVectorAttribute(QtProperty *prop);
116
118 void updateParameters();
119
121 void updateAttributes();
122
124 void updateErrors();
125
127 void clearErrors();
128
129 // Get property for function parameter parName
130 QtProperty *getParameterProperty(const QString &parName) const;
131
132 // Get parameter property which has the argument as a child (i.e. tie or
133 // conatraint)
134 QtProperty *getParameterProperty(QtProperty *prop) const;
135
140 std::shared_ptr<Mantid::API::IFunction> changeType(QtProperty *prop);
141
142 void setHeight(const double &h);
143 void setCentre(const double &c);
144 void setFwhm(const double &w);
145 void setBase(const double &b) { m_base = b; }
146 void calcBase(); //< caclulate baseline from workspace data
147 void calcBaseAll(); //< calc baseline for all peaks in the function
149 double EstimateFwhm() const;
150
151 double height() const;
152 double centre() const;
153 double fwhm() const;
154 std::string getWidthParameterName() const;
155 std::string getCentreParameterName() const;
156 bool isParameterExplicitlySet(const std::string &param) const;
157 double base() const { return m_base; }
158
159 void addTie(const QString &tieStr);
160 void fix(const QString &parName);
161 void removeTie(QtProperty *prop, const std::string &globalName);
162 void removeTie(QtProperty *prop);
163 void removeTie(const QString &propName);
164 void addConstraint(QtProperty *parProp, bool lo, bool up, double loBound, double upBound);
165 void removeConstraint(QtProperty *parProp);
166
167 // Return list of handlers of peak functions which can be used in
168 // PeakPickerTool
169 // The item->pfun() will return a correct pointer to a peak
170 // Non-const because it may return a non-const pointer to this.
171 QList<PropertyHandler *> getPeakList();
172
173 // Plot the function on a graph
174 bool hasPlot() const { return m_hasPlot; }
175 void setHasPlot(const bool state) { m_hasPlot = state; };
176 void removeAllPlots();
177
178 void fit();
179
180 // update workspace property when workspaces added to or removed from ADS
181 void updateWorkspaces(const QStringList &oldWorkspaces);
182 // set workspace in workspace property to the function
183 void setFunctionWorkspace();
184
186 QString updateStructureTooltip();
187
188 const QMap<QString, QtProperty *> &getTies() { return m_ties; };
189 bool hasTies() { return !m_ties.isEmpty(); };
190
191protected slots:
192
193 //
194 void plotRemoved();
195
196protected:
197 void initAttributes();
198 void initParameters();
199 void initWorkspace();
200 void initTies();
201
202private:
204 std::shared_ptr<Mantid::API::CompositeFunction> m_cf; //< if the function is composite holds pointer to it
205 std::shared_ptr<Mantid::API::IPeakFunction> m_pf; //< if the function is peak holds pointer to it
206 std::shared_ptr<Mantid::API::CompositeFunction> m_parent; //< if the function has parent holds pointer to it
207 QtProperty *m_type;
208 QtBrowserItem *m_item; //< the browser item
209 QList<QtProperty *> m_attributes; //< function attribute properties
210 QList<QtProperty *> m_parameters; //< function parameter properties
211 QMap<QString, QtProperty *> m_ties; //< tie properties
212 QMap<QString, std::pair<QtProperty *, QtProperty *>> m_constraints; //< constraints
213 QList<QtProperty *> m_vectorMembers; //< vector member properties
214 QList<QtProperty *> m_vectorSizes; //< vector size properties
217 QtProperty *m_workspace;
218 QtProperty *m_workspaceIndex;
219 double m_base; //< the baseline for a peak
220 int m_ci; //< approximate index in the workspace at the peak centre
221 // mutable FunctionCurve* m_curve;//< the curve to plot the handled function
222 mutable bool m_hasPlot;
223
225 void updateParameter(QtProperty *prop);
226
228 void updateError(QtProperty *prop);
229
231 void clearError(QtProperty *prop);
232
234 void applyToAllParameters(void (PropertyHandler::*func)(QtProperty *));
235
237 void updateAttribute(QtProperty *prop);
238
240 void applyToAllAttributes(void (PropertyHandler::*func)(QtProperty *));
241
243};
244
245} // namespace MantidWidgets
246} // namespace MantidQt
#define EXPORT_OPT_MANTIDQT_COMMON
Definition DllOption.h:15
double height
Definition GetAllEi.cpp:155
Attribute visitor to create a QtProperty.
Class FitPropertyBrowser implements QtPropertyBrowser to display and control fitting function paramet...
Helps display and edit functions in FitPropertyBrowser.
std::shared_ptr< Mantid::API::IPeakFunction > pfun() const
QtProperty * m_workspaceIndex
workspace index for multispectral fitting
std::shared_ptr< Mantid::API::CompositeFunction > m_cf
const QMap< QString, QtProperty * > & getTies()
std::shared_ptr< Mantid::API::IPeakFunction > m_pf
std::shared_ptr< Mantid::API::IFunction > ifun() const
std::shared_ptr< Mantid::API::CompositeFunction > cfun() const
QMap< QString, std::pair< QtProperty *, QtProperty * > > m_constraints
QMap< QString, QtProperty * > m_ties
bool m_isMultispectral
true if fitting to multiple spectra using MultiBG
std::shared_ptr< Mantid::API::CompositeFunction > m_parent
A composite function is a function containing other functions.
Classes inherited from FunctionHandler will handle the function.
Definition IFunction.h:754
Attribute is a non-fitting parameter.
Definition IFunction.h:285
This is an interface to a fitting function - a semi-abstarct class.
Definition IFunction.h:166
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:743
std::shared_ptr< const IFunction > IFunction_const_sptr
shared pointer to the function base class (const version)
Definition IFunction.h:745
Helper class which provides the Collimation Length for SANS instruments.