Mantid
Loading...
Searching...
No Matches
FunctionTreeView.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
16
17#include <QMap>
18#include <QRect>
19#include <QStringList>
20#include <QWidget>
21
22/* Forward declarations */
23
24class QtTreePropertyBrowser;
25class QtGroupPropertyManager;
26class QtDoublePropertyManager;
27class QtIntPropertyManager;
28class QtBoolPropertyManager;
29class QtStringPropertyManager;
30class QtEnumPropertyManager;
31class QtProperty;
32class QtBrowserItem;
33class ParameterPropertyManager;
34class DoubleDialogEditorFactory;
35
36class QPushButton;
37class QLabel;
38class QLineEdit;
39class QComboBox;
40class QSignalMapper;
41class QMenu;
42class QAction;
43class QTreeWidget;
44class QTreeWidgetItem;
45
46namespace Mantid {
47namespace API {
48class Workspace;
49class ParameterTie;
50} // namespace API
51} // namespace Mantid
52
53namespace MantidQt {
54namespace MantidWidgets {
55
56class CreateAttributePropertyForFunctionTreeView;
57class SelectFunctionDialog;
58struct GlobalTie;
59
67 Q_OBJECT
68public:
70 struct AProperty {
71 QtProperty *prop;
72 QtBrowserItem *item;
73 QtProperty *parent;
74 };
76 struct ATie {
77 QtProperty *paramProp;
78 QString paramName;
79 QtProperty *tieProp;
80 };
82 struct AConstraint {
83 QtProperty *paramProp;
84 QtProperty *lower;
85 QtProperty *upper;
86 };
87
89 FunctionTreeView(QWidget *parent, bool multi, std::vector<std::string> categories = std::vector<std::string>());
91 ~FunctionTreeView() override;
93 void clear() override;
95 void setFunction(Mantid::API::IFunction_sptr fun) override;
97 bool hasFunction() const override;
99 void setParameter(const QString &paramName, double value) override;
101 void setParameterError(const QString &paramName, double error) override;
103 double getParameter(const QString &paramName) const override;
105 IFunction::Attribute getAttribute(const QString &attrName) const override;
107 void setErrorsEnabled(bool enabled) override;
109 void clearErrors() override;
111 boost::optional<QString> currentFunctionIndex() const override;
113 void setParameterTie(const QString &paramName, const QString &tie) override;
115 void setParameterConstraint(const QString &paramName, const QString &constraint) override;
117 void setGlobalParameters(const QStringList &) override;
119 QStringList getGlobalParameters() const;
120
121 IFunction_sptr getSelectedFunction() override;
122 void showFunctionHelp(const QString &functionName) const override;
123
125 Mantid::API::IFunction_sptr getFunction(QtProperty *prop = nullptr, bool attributesOnly = false);
127 void setColumnSizes(int s0, int s1, int s2 = -1);
129 void setStretchLastColumn(bool stretch);
130
131 // Hide global boxes
132 void hideGlobals();
133 // Show global boxes
134 void showGlobals();
135
136 // Sets the function prefix of a domain to be displayed within a
137 // MultiDomainFunction
138 void setMultiDomainFunctionPrefix(const QString &functionPrefix);
139 // Sets the global ties to be displayed within a MultiDomainFunction
140 void setGlobalTies(std::vector<GlobalTie> const &globalTies);
141
142protected:
144 void createBrowser();
146 void createActions();
148 AProperty addProperty(QtProperty *parent, QtProperty *subproperty);
150 void removeProperty(QtProperty *prop);
152 void setFunction(QtProperty *prop, const Mantid::API::IFunction_sptr &fun);
154 bool addFunction(QtProperty *prop, const Mantid::API::IFunction_sptr &fun);
156 AProperty addFunctionProperty(QtProperty *parent, const QString &funName);
158 AProperty addParameterProperty(QtProperty *parent, const QString &paramName, const QString &paramDesc,
159 double paramValue);
161 AProperty addAttributeProperty(QtProperty *parent, const QString &attName,
164 void addAttributeAndParameterProperties(QtProperty *prop, const Mantid::API::IFunction_sptr &fun,
165 const Mantid::API::CompositeFunction_sptr &parentComposite = nullptr,
166 const std::size_t &parentIndex = 0);
169 void addParameterTie(QtProperty *property, const Mantid::API::IFunction_sptr &function,
170 const std::string &parameterName, const std::size_t &parameterIndex,
171 const Mantid::API::CompositeFunction_sptr &parentComposite = nullptr,
172 const std::size_t &parentIndex = 0);
174 bool addParameterTieInComposite(QtProperty *property, const std::string &parameterName,
175 const Mantid::API::CompositeFunction_sptr &composite, const std::size_t &index);
177 void addGlobalParameterTie(QtProperty *property, const std::string &parameterName,
178 const CompositeFunction_sptr &parentComposite = nullptr,
179 const std::size_t &parentIndex = 0);
182 void addMultiDomainIndexProperty(QtProperty *prop);
184 AProperty addIndexProperty(QtProperty *prop);
186 void updateFunctionIndices(QtProperty *prop = nullptr, const QString &index = "");
188 AProperty getFunctionProperty() const;
190 bool isFunction(QtProperty *prop) const;
192 bool isAttribute(QtProperty *prop) const;
194 bool isStringAttribute(QtProperty *prop) const;
196 bool isDoubleAttribute(QtProperty *prop) const;
198 bool isIntAttribute(QtProperty *prop) const;
200 bool isBoolAttribute(QtProperty *prop) const;
202 bool isVectorAttribute(QtProperty *prop) const;
204 bool isParameter(QtProperty *prop) const;
206 double getParameter(QtProperty *prop) const;
208 bool isIndex(QtProperty *prop) const;
210 QString getIndex(QtProperty *prop) const;
212 QString getParameterName(QtProperty *prop) const;
214 QString getAttributeName(QtProperty *prop) const;
216 QtProperty *getFunctionProperty(const QString &index) const;
219 QtProperty *getParameterProperty(const QString &paramName) const;
221 QtProperty *getAttributeProperty(const QString &paramName) const;
224 QtProperty *getParentParameterProperty(QtProperty *prop) const;
226 QtProperty *getTieProperty(QtProperty *prop) const;
227
229 void addTieProperty(QtProperty *prop, const QString &tie, bool globalTie = false);
231 bool hasTie(QtProperty *prop) const;
233 bool isTie(QtProperty *prop) const;
235 QString getTie(QtProperty *prop) const;
236
238 QList<AProperty> addConstraintProperties(QtProperty *prop, const QString &constraint);
240 bool isConstraint(QtProperty *prop) const;
242 bool hasConstraint(QtProperty *prop) const;
244 bool hasLowerBound(QtProperty *prop) const;
246 bool hasUpperBound(QtProperty *prop) const;
248 QString getConstraint(const QString &paramName, const double &lowerBound = Mantid::EMPTY_DBL(),
249 const double &upperBound = Mantid::EMPTY_DBL()) const;
252 std::pair<QString, QString> getFunctionAndConstraint(QtProperty *prop) const;
253
254protected slots:
256 void popupMenu(const QPoint &);
258 void addFunctionBegin();
259 void addFunctionEnd(int result);
261 void removeFunction();
263 void fixParameter();
265 void removeTie();
267 void addTie();
269 void pasteFromClipboard();
271 void copyToClipboard();
273 void addConstraints();
275 void removeConstraints();
277 void addConstraints10();
279 void addConstraints50();
281 void removeConstraint();
283 void updateCurrentFunctionIndex();
284 // Property change slots
286 void attributeChanged(QtProperty *);
288 void attributeVectorDoubleChanged(QtProperty *);
290 void attributeVectorSizeChanged(QtProperty *);
292 void parameterPropertyChanged(QtProperty *);
294 void parameterButtonClicked(QtProperty *);
296 void tieChanged(QtProperty *);
298 void constraintChanged(QtProperty *);
300 void globalChanged(QtProperty *, const QString &, bool);
302 void setAttributeToFunction(Mantid::API::IFunction &fun, QtProperty *prop);
303
304protected:
305 void removeConstraintsQuiet(QtProperty *paramProp);
306
308 DoubleDialogEditorFactory *m_doubleEditorFactory;
310 QtGroupPropertyManager *m_functionManager;
312 ParameterPropertyManager *m_parameterManager;
314 QtStringPropertyManager *m_attributeStringManager;
316 QtDoublePropertyManager *m_attributeDoubleManager;
318 QtIntPropertyManager *m_attributeIntManager;
320 QtBoolPropertyManager *m_attributeBoolManager;
322 QtStringPropertyManager *m_indexManager;
324 QtStringPropertyManager *m_tieManager;
326 QtDoublePropertyManager *m_constraintManager;
328 QtStringPropertyManager *m_filenameManager;
330 QtStringPropertyManager *m_formulaManager;
332 QtStringPropertyManager *m_workspaceManager;
334 QtGroupPropertyManager *m_attributeVectorManager;
336 QtDoublePropertyManager *m_attributeVectorDoubleManager;
338 QtIntPropertyManager *m_attributeSizeManager;
339
341 QtTreePropertyBrowser *m_browser;
343 QMap<QtProperty *, AProperty> m_properties;
348
349 // Actions
350
379 boost::optional<QString> m_currentFunctionIndex;
386 // A vector of global ties. E.g. f0.f0.A0=f1.f0.A0
387 std::vector<GlobalTie> m_globalTies;
388 std::vector<std::string> m_allowedCategories;
391 bool m_emitParameterValueChange = true;
392 bool m_emitAttributeValueChange = true;
393
396
397private:
399 void setDoubleAttribute(const QString &attrName, double value) override;
400 void setIntAttribute(const QString &attrName, int value) override;
401 void setStringAttribute(const QString &attrName, std::string &value) override;
402 void setBooleanAttribute(const QString &attrName, bool value) override;
403 void setVectorAttribute(const QString &attrName, std::vector<double> &val) override;
404
406 QString getFullTie(const QString &tie) const;
408 std::string getFullParameterName(const std::string &parameter, int compositeIndex = -1) const;
409
410 // Intended for testing only
411 QTreeWidgetItem *getPropertyWidgetItem(QtProperty *prop) const;
412 QRect visualItemRect(QtProperty *prop) const;
413
414public:
415 // Intended for testing only
416 int getNumberOfQtProperties() const { return m_properties.size(); }
417 int getNumberOfTieProperties() const { return m_ties.size(); }
418 int getNumberOfConstraintProperties() const { return m_constraints.size(); }
419 QRect getVisualRectFunctionProperty(const QString &index) const;
420 QRect getVisualRectParameterProperty(const QString &paramName) const;
421 QTreeWidget *treeWidget() const;
422 QtTreePropertyBrowser *treeBrowser();
423 DoubleDialogEditorFactory *doubleEditorFactory();
424 QWidget *getParamWidget(const QString &paramName) const;
425};
426
427} // namespace MantidWidgets
428} // 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
std::map< DeltaEMode::Type, std::string > index
Definition: DeltaEMode.cpp:19
Class FitPropertyBrowser implements QtPropertyBrowser to display and control fitting function paramet...
QAction * m_actionRemoveConstraint
Remove one constraints from current parameter.
QtStringPropertyManager * m_attributeStringManager
Manager for function string attribute properties.
QAction * m_actionRemoveTie
Unfix a parameter.
QAction * m_actionFixParameter
Fix a parameter.
QtIntPropertyManager * m_attributeSizeManager
Manager for vector attribute size properties.
QtGroupPropertyManager * m_functionManager
Manager for function group properties.
bool m_multiDataset
Set true if the constructed function is intended to be used in a multi-dataset fit.
QtGroupPropertyManager * m_attributeVectorManager
Manager for vector attribute properties.
QAction * m_actionFromClipboard
Copy a function from the clipboard.
QAction * m_actionFunctionHelp
Show function help menu.
QtStringPropertyManager * m_workspaceManager
Manager for Workspace attributes.
QtTreePropertyBrowser * m_browser
Qt property browser which displays properties.
QAction * m_actionConstraints50
Add both constraints to current parameter with 50% spread.
QtDoublePropertyManager * m_attributeVectorDoubleManager
Manager for vector attribute member properties.
QAction * m_actionConstraints
Add both constraints to current parameter.
QAction * m_actionConstraints10
Add both constraints to current parameter with 10% spread.
QtStringPropertyManager * m_filenameManager
Manager for file name attributes.
QAction * m_actionToClipboard
Copy a function to the clipboard.
QtDoublePropertyManager * m_attributeDoubleManager
Manager for function double attribute properties.
QAction * m_actionRemoveConstraints
Remove both constraints from current parameter.
QString m_multiDomainFunctionPrefix
The function prefix of the domain with a MultiDomainFunction currently being displayed.
boost::optional< QString > m_currentFunctionIndex
Index of currently selected function.
QtDoublePropertyManager * m_constraintManager
Manager for parameter constraint properties.
std::vector< std::string > m_allowedCategories
QMultiMap< QtProperty *, ATie > m_ties
Store parameter ties. Keys are function properties.
QMap< QtProperty *, AProperty > m_properties
Store all properties in a map for easy access.
QAction * m_actionAddTie
Add a custom tie to a parameter.
QtIntPropertyManager * m_attributeIntManager
Manager for function int attribute properties.
QtBoolPropertyManager * m_attributeBoolManager
Manager for function bool attribute properties.
QtStringPropertyManager * m_tieManager
Manager for function tie properties.
ParameterPropertyManager * m_parameterManager
Manager for function parameter properties.
QtStringPropertyManager * m_formulaManager
Manager for Formula attributes.
QAction * m_actionAddFunction
Add a function.
QMultiMap< QtProperty *, AConstraint > m_constraints
Store parameter constraints. Keys are function properties.
DoubleDialogEditorFactory * m_doubleEditorFactory
Editor used for editing doubles.
QAction * m_actionRemoveFunction
Remove a function.
QtStringPropertyManager * m_indexManager
Manager for function index properties.
The interface to a function view.
Definition: IFunctionView.h:26
Select a function type out of a list of available ones.
Attribute visitor to set an attribute from a QtProperty.
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< CompositeFunction > CompositeFunction_sptr
shared pointer to the composite function base class
Helper class which provides the Collimation Length for SANS instruments.
constexpr double EMPTY_DBL() noexcept
Returns what we consider an "empty" double within a property.
Definition: EmptyValues.h:43
To keep QtProperty and its QtBrowserItem in one place.
QtProperty * paramProp
Parameter property.