-
Notifications
You must be signed in to change notification settings - Fork 122
/
FunctionBrowser.h
387 lines (345 loc) · 13.7 KB
/
FunctionBrowser.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
#ifndef MANTIDWIDGETS_FUNCTIONBROWSER_H_
#define MANTIDWIDGETS_FUNCTIONBROWSER_H_
#include "WidgetDllOption.h"
#include "MantidAPI/IFunction.h"
#include <QWidget>
#include <QMap>
#include <boost/optional.hpp>
/* Forward declarations */
class QtTreePropertyBrowser;
class QtGroupPropertyManager;
class QtDoublePropertyManager;
class QtIntPropertyManager;
class QtBoolPropertyManager;
class QtStringPropertyManager;
class QtEnumPropertyManager;
class QtProperty;
class QtBrowserItem;
class ParameterPropertyManager;
class QPushButton;
class QLabel;
class QLineEdit;
class QComboBox;
class QSignalMapper;
class QMenu;
class QAction;
class QTreeWidget;
namespace Mantid
{
namespace API
{
class CompositeFunction;
class Workspace;
class ParameterTie;
}
}
namespace MantidQt
{
namespace MantidWidgets
{
class CreateAttributePropertyForFunctionBrowser;
/**
* Class FitPropertyBrowser implements QtPropertyBrowser to display
* and control fitting function parameters and settings.
*
* @date 18/04/2012
*/
class EXPORT_OPT_MANTIDQT_MANTIDWIDGETS FunctionBrowser: public QWidget
{
Q_OBJECT
public:
/// To keep QtProperty and its QtBrowserItem in one place
struct AProperty
{
QtProperty *prop;
QtBrowserItem *item;
QtProperty *parent;
};
/// Tie structure
struct ATie
{
QtProperty *paramProp; ///< Parameter property
QtProperty *tieProp; ///< Tie property
};
/// Constraint structure
struct AConstraint
{
QtProperty *paramProp; ///< Parameter property
QtProperty *lower; ///< Constraint property
QtProperty *upper; ///< Constraint property
};
/// Constructor
FunctionBrowser(QWidget *parent = NULL, bool multi = false);
/// Destructor
~FunctionBrowser();
/// Clear the contents
void clear();
/// Set the function in the browser
void setFunction(const QString& funStr);
/// Set the function in the browser
void setFunction(Mantid::API::IFunction_sptr fun);
/// Return FunctionFactory function string
QString getFunctionString();
/// Return the function
Mantid::API::IFunction_sptr getFunction(QtProperty* prop = NULL, bool attributesOnly = false);
/// Check if a function is set
bool hasFunction() const;
/// Return a function with specified index
Mantid::API::IFunction_sptr getFunctionByIndex(const QString& index);
/// Return index of the current function, if one is selected
boost::optional<QString> currentFunctionIndex() { return m_currentFunctionIndex; }
/// Update the function parameter value
void setParameter(const QString& funcIndex, const QString& paramName, double value);
/// Update the function parameter error
void setParamError(const QString& funcIndex, const QString& paramName, double error);
/// Get a value of a parameter
double getParameter(const QString& funcIndex, const QString& paramName) const;
/// Update the function parameter value
void setParameter(const QString& paramName, double value);
/// Update the function parameter error
void setParamError(const QString& paramName, double error);
/// Get a value of a parameter
double getParameter(const QString& paramName) const;
/// Update parameter values in the browser to match those of a function.
void updateParameters(const Mantid::API::IFunction& fun);
/// Get a list of names of global parameters
QStringList getGlobalParameters() const;
/// Get a list of names of local parameters
QStringList getLocalParameters() const;
/// Get the number of datasets
int getNumberOfDatasets() const;
/// Get value of a local parameter
double getLocalParameterValue(const QString& parName, int i) const;
/// Set value of a local parameter
void setLocalParameterValue(const QString& parName, int i, double value);
/// Check if a local parameter is fixed
bool isLocalParameterFixed(const QString& parName, int i) const;
/// Fix/unfix local parameter
void setLocalParameterFixed(const QString& parName, int i, bool fixed);
/// Return the multidomain function if number of datasets is greater than 1
Mantid::API::IFunction_sptr getGlobalFunction();
/// Update parameter values in the browser to match those of a function.
void updateMultiDatasetParameters(const Mantid::API::IFunction& fun);
signals:
/// User selects a different function (or one of it's sub-properties)
void currentFunctionChanged();
/// Function parameter gets changed
/// @param funcIndex :: Index of the changed function
/// @param paramName :: Name of the changed parameter
void parameterChanged(const QString& funcIndex, const QString& paramName);
/// In multi-dataset context a button value editor was clicked
void localParameterButtonClicked(const QString& parName);
void functionStructureChanged();
public slots:
// Handling of multiple datasets
void setNumberOfDatasets(int n);
void resetLocalParameters();
void setCurrentDataset(int i);
void removeDatasets(QList<int> indices);
void addDatasets(int n);
protected:
/// Create the Qt property browser
void createBrowser();
/// Create and connect actions
void createActions();
/// Add a sub-property
AProperty addProperty(QtProperty* parent, QtProperty* subproperty);
/// Remove and delete property
void removeProperty(QtProperty *prop);
/// Set a function
void setFunction(QtProperty* prop, Mantid::API::IFunction_sptr fun);
/// Add a function
void addFunction(QtProperty* prop, Mantid::API::IFunction_sptr fun);
/// Add a function property
AProperty addFunctionProperty(QtProperty* parent, QString funName);
/// Add a parameter property
AProperty addParameterProperty(QtProperty* parent, QString paramName, QString paramDesc, double paramValue);
/// Add a attribute property
AProperty addAttributeProperty(QtProperty* parent, QString attName, const Mantid::API::IFunction::Attribute& att);
/// Add attribute and parameter properties to a function property
void addAttributeAndParameterProperties(QtProperty* prop, Mantid::API::IFunction_sptr fun);
/// Add property showing function's index in the composite function
AProperty addIndexProperty(QtProperty* prop);
/// Update function index properties
void updateFunctionIndices(QtProperty* prop = NULL, QString index = "");
/// Get property of the overall function
AProperty getFunctionProperty() const;
/// Check if property is a function group
bool isFunction(QtProperty* prop) const;
/// Check if property is a function attribute
bool isAttribute(QtProperty* prop) const;
/// Check if property is a string attribute
bool isStringAttribute(QtProperty* prop) const;
/// Check if property is a double attribute
bool isDoubleAttribute(QtProperty* prop) const;
/// Check if property is a int attribute
bool isIntAttribute(QtProperty* prop) const;
/// Check if property is a bool attribute
bool isBoolAttribute(QtProperty* prop) const;
/// Check if property is a vector attribute
bool isVectorAttribute(QtProperty* prop) const;
/// Check if property is a function paramater
bool isParameter(QtProperty* prop) const;
/// Get attribute as a string
double getParameter(QtProperty* prop) const;
/// Check if a property is an index
bool isIndex(QtProperty* prop) const;
/// Get the function index for a property
QString getIndex(QtProperty* prop) const;
/// Get function property for the index
QtProperty* getFunctionProperty(const QString& index)const;
/// Split a qualified parameter name into function index and local parameter name.
QStringList splitParameterName(const QString& paramName) const;
/// Get a property for a parameter
QtProperty* getParameterProperty(const QString& paramName) const;
/// Get a property for a parameter
QtProperty* getParameterProperty(const QString& funcIndex, const QString& paramName) const;
/// Get a tie property attached to a parameter property
QtProperty* getTieProperty(QtProperty* prop) const;
/// Add a tie property
AProperty addTieProperty(QtProperty* prop, QString tie);
/// Check if a parameter property has a tie
bool hasTie(QtProperty* prop) const;
/// Check if a property is a tie
bool isTie(QtProperty* prop) const;
/// Get a tie for a paramater
std::string getTie(QtProperty* prop) const;
/// Add a constraint property
QList<AProperty> addConstraintProperties(QtProperty* prop, QString constraint);
/// Check if a property is a constraint
bool isConstraint(QtProperty* prop) const;
/// Check if a parameter property has a constraint
bool hasConstraint(QtProperty* prop) const;
/// Check if a parameter property has a lower bound
bool hasLowerBound(QtProperty* prop) const;
/// Check if a parameter property has a upper bound
bool hasUpperBound(QtProperty* prop) const;
/// Initialize storage and values for local parameters
void initLocalParameter(const QString& parName)const;
/// Make sure that the parameter is initialized
void checkLocalParameter(const QString& parName)const;
/// Make sure that properties are in sync with the cached ties
void updateLocalTie(const QString& parName);
protected slots:
/// Show the context menu
void popupMenu(const QPoint &);
/// Add a function
void addFunction();
/// Remove a function
void removeFunction();
/// Fix a parameter
void fixParameter();
/// Unfix a parameter
void removeTie();
/// Add a tie to a parameter
void addTie();
/// Copy function from the clipboard
void copyFromClipboard();
/// Copy the function to the clipboard
void copyToClipboard();
/// Add both constraints to current parameter
void addConstraints();
/// Remove both constraints from current parameter
void removeConstraints();
/// Add both constraints to current parameter
void addConstraints10();
/// Add both constraints to current parameter
void addConstraints50();
/// Remove one of the constraints
void removeConstraint();
/// Update current function index depending on currently selected item
void updateCurrentFunctionIndex();
// Property change slots
/// Called when a function attribute property is changed
void attributeChanged(QtProperty*);
/// Called when a member of a vector attribute is changed
void attributeVectorDoubleChanged(QtProperty*);
/// Called when a function parameter property is changed
void parameterChanged(QtProperty*);
void parameterButtonClicked(QtProperty*);
protected:
/// Manager for function group properties
QtGroupPropertyManager *m_functionManager;
/// Manager for function parameter properties
ParameterPropertyManager *m_parameterManager;
/// Manager for function string attribute properties
QtStringPropertyManager *m_attributeStringManager;
/// Manager for function double attribute properties
QtDoublePropertyManager *m_attributeDoubleManager;
/// Manager for function int attribute properties
QtIntPropertyManager *m_attributeIntManager;
/// Manager for function bool attribute properties
QtBoolPropertyManager *m_attributeBoolManager;
/// Manager for function index properties
QtStringPropertyManager *m_indexManager;
/// Manager for function tie properties
QtStringPropertyManager *m_tieManager;
/// Manager for parameter constraint properties
QtStringPropertyManager *m_constraintManager;
/// Manager for file name attributes
QtStringPropertyManager *m_filenameManager;
/// Manager for Formula attributes
QtStringPropertyManager *m_formulaManager;
/// Manager for Workspace attributes
QtStringPropertyManager *m_workspaceManager;
/// Manager for vector attribute properties
QtGroupPropertyManager *m_attributeVectorManager;
/// Manager for vector attribute member properties
QtDoublePropertyManager *m_attributeVectorDoubleManager;
/// Manager for vector attribute size properties
QtIntPropertyManager *m_attributeSizeManager;
/// Qt property browser which displays properties
QtTreePropertyBrowser* m_browser;
/// Store all properties in a map for easy access
QMap<QtProperty*,AProperty> m_properties;
/// Store parameter ties. Keys are function properties.
QMultiMap<QtProperty*,ATie> m_ties;
/// Store parameter constraints. Keys are function properties.
QMultiMap<QtProperty*,AConstraint> m_constraints;
// Actions
/// Add a function
QAction *m_actionAddFunction;
/// Remove a function
QAction *m_actionRemoveFunction;
/// Fix a parameter
QAction *m_actionFixParameter;
/// Unfix a parameter
QAction *m_actionRemoveTie;
/// Add a custom tie to a parameter
QAction *m_actionAddTie;
/// Copy a function from the clipboard
QAction *m_actionFromClipboard;
/// Copy a function to the clipboard
QAction *m_actionToClipboard;
/// Add both constraints to current parameter with 10% spread
QAction *m_actionConstraints10;
/// Add both constraints to current parameter with 50% spread
QAction *m_actionConstraints50;
/// Add both constraints to current parameter
QAction *m_actionConstraints;
/// Remove both constraints from current parameter
QAction *m_actionRemoveConstraints;
/// Remove one constraints from current parameter
QAction *m_actionRemoveConstraint;
/// Index of currently selected function. Gets updated in updateCurrentFunctionIndex()
boost::optional<QString> m_currentFunctionIndex;
struct LocalParameterData
{
explicit LocalParameterData(double v = 0.0):value(v),fixed(false){}
double value;
bool fixed;
};
/// Set true if the constructed function is intended to be used in a multi-dataset fit
bool m_multiDataset;
/// Number of datasets this function is used for
int m_numberOfDatasets;
/// Storage for local paramter values
mutable QMap<QString,QVector<LocalParameterData>> m_localParameterValues;
/// Index of a dataset for which the parameters are currently displayed
int m_currentDataset;
friend class CreateAttributePropertyForFunctionBrowser;
friend class SetAttributeFromProperty;
};
} // MantidWidgets
} // MantidQt
#endif /*MANTIDWIDGETS_FUNCTIONBROWSER_H_*/