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;
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
109 bool setAttribute(QtProperty *prop, bool resetProperties = true);
110
116 void setAttribute(QString const &attName, Mantid::API::IFunction::Attribute const &attValue);
117
123 template <typename AttributeType> void setAttribute(QString const &attName, AttributeType const &attValue);
124
131 void setAttribute(const QString &attName, const QString &attValue);
132
134 void setVectorAttribute(QtProperty *prop);
135
137 void updateParameters();
138
140 void updateAttributes();
141
143 void updateErrors();
144
146 void clearErrors();
147
148 // Get property for function parameter parName
149 QtProperty *getParameterProperty(const QString &parName) const;
150
151 // Get parameter property which has the argument as a child (i.e. tie or
152 // conatraint)
153 QtProperty *getParameterProperty(QtProperty *prop) const;
154
159 std::shared_ptr<Mantid::API::IFunction> changeType(QtProperty *prop);
160
161 void setHeight(const double &h);
162 void setCentre(const double &c);
163 void setFwhm(const double &w);
164 void setBase(const double &b) { m_base = b; }
165 void calcBase(); //< caclulate baseline from workspace data
166 void calcBaseAll(); //< calc baseline for all peaks in the function
168 double EstimateFwhm() const;
169
170 double height() const;
171 double centre() const;
172 double fwhm() const;
173 std::string getWidthParameterName() const;
174 std::string getCentreParameterName() const;
175 bool isParameterExplicitlySet(const std::string &param) const;
176 double base() const { return m_base; }
177
178 void addTie(const QString &tieStr);
179 void fix(const QString &parName);
180 void removeTie(QtProperty *prop, const std::string &globalName);
181 void removeTie(QtProperty *prop);
182 void removeTie(const QString &propName);
183 void addConstraint(QtProperty *parProp, bool lo, bool up, double loBound, double upBound);
184 void removeConstraint(QtProperty *parProp);
185
186 // Return list of handlers of peak functions which can be used in
187 // PeakPickerTool
188 // The item->pfun() will return a correct pointer to a peak
189 // Non-const because it may return a non-const pointer to this.
190 QList<PropertyHandler *> getPeakList();
191
192 // Plot the function on a graph
193 bool hasPlot() const { return m_hasPlot; }
194 void setHasPlot(const bool state) { m_hasPlot = state; };
195 void removeAllPlots();
196
197 void fit();
198
199 // update workspace property when workspaces added to or removed from ADS
200 void updateWorkspaces(QStringList oldWorkspaces);
201 // set workspace in workspace property to the function
202 void setFunctionWorkspace();
203
205 QString updateStructureTooltip();
206
207 QMap<QString, QtProperty *> getTies() { return m_ties; };
208 bool hasTies() { return !m_ties.isEmpty(); };
209
210protected slots:
211
212 //
213 void plotRemoved();
214
215protected:
216 void initAttributes();
217 void initParameters();
218 void initWorkspace();
219 void initTies();
220
221private:
223 std::shared_ptr<Mantid::API::CompositeFunction> m_cf; //< if the function is composite holds pointer to it
224 std::shared_ptr<Mantid::API::IPeakFunction> m_pf; //< if the function is peak holds pointer to it
225 std::shared_ptr<Mantid::API::CompositeFunction> m_parent; //< if the function has parent holds pointer to it
226 QtProperty *m_type;
227 QtBrowserItem *m_item; //< the browser item
228 QList<QtProperty *> m_attributes; //< function attribute properties
229 QList<QtProperty *> m_parameters; //< function parameter properties
230 QMap<QString, QtProperty *> m_ties; //< tie properties
231 QMap<QString, std::pair<QtProperty *, QtProperty *>> m_constraints; //< constraints
232 QList<QtProperty *> m_vectorMembers; //< vector member properties
233 QList<QtProperty *> m_vectorSizes; //< vector size properties
236 QtProperty *m_workspace;
237 QtProperty *m_workspaceIndex;
238 double m_base; //< the baseline for a peak
239 int m_ci; //< approximate index in the workspace at the peak centre
240 // mutable FunctionCurve* m_curve;//< the curve to plot the handled function
241 mutable bool m_hasPlot;
242
244 void updateParameter(QtProperty *prop);
245
247 void updateError(QtProperty *prop);
248
250 void clearError(QtProperty *prop);
251
253 void applyToAllParameters(void (PropertyHandler::*func)(QtProperty *));
254
256 void updateAttribute(QtProperty *prop);
257
259 void applyToAllAttributes(void (PropertyHandler::*func)(QtProperty *));
260
262};
263
264} // namespace MantidWidgets
265} // 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
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
Classes inherited from FunctionHandler will handle the function.
Definition: IFunction.h:743
Attribute is a non-fitting parameter.
Definition: IFunction.h:282
This is an interface to a fitting function - a semi-abstarct class.
Definition: IFunction.h:163
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
std::shared_ptr< const IFunction > IFunction_const_sptr
shared pointer to the function base class (const version)
Definition: IFunction.h:734
Helper class which provides the Collimation Length for SANS instruments.