Mantid
Loading...
Searching...
No Matches
FitPropertyBrowser.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"
12
13#include <QDockWidget>
14#include <QHash>
15#include <QList>
16#include <QMap>
17
20#include "MantidAPI/IFunction.h"
27
28/* Forward declarations */
29
30class QtTreePropertyBrowser;
31class QtGroupPropertyManager;
32class QtDoublePropertyManager;
33class QtIntPropertyManager;
34class QtBoolPropertyManager;
35class QtStringPropertyManager;
36class QtEnumPropertyManager;
37class ParameterPropertyManager;
38
39class QtProperty;
40class QtBrowserItem;
41
42class QAction;
43class QComboBox;
44class QLabel;
45class QLineEdit;
46class QListWidget;
47class QListWidgetItem;
48class QMenu;
49class QPushButton;
50class QSignalMapper;
51class QTreeWidget;
52class QVBoxLayout;
53
54namespace MantidQt {
55namespace MantidWidgets {
56
57class PropertyHandler;
58class SelectFunctionDialog;
70 Q_OBJECT
71public:
73 FitPropertyBrowser(QWidget *parent = nullptr, QObject *mantidui = nullptr);
75 ~FitPropertyBrowser() override;
77 PropertyHandler *getHandler() const;
79 virtual void init();
80
82 double centre() const;
84 void setCentre(double value);
86 double height() const;
88 void setHeight(double value);
90 double fwhm() const;
92 void setFwhm(double value);
94 int count() const;
96 bool isPeak() const;
98 PropertyHandler *currentHandler() const;
100 void setCurrentFunction(PropertyHandler *h) const;
102 std::shared_ptr<const Mantid::API::IFunction> theFunction() const;
104 void updateParameters();
106 void updateAttributes();
108 QList<double> getParameterValues() const;
110 QStringList getParameterNames() const;
111 // Get parameters used to run the Fit algorithm
112 const std::string &getFitAlgorithmParameters() const;
113 // Get the status string returned from Fit
114 const std::string &getFitAlgorithmOutputStatus() const;
115
117 void loadFunction(const QString &funcString);
119 void saveFunction(const QString &fnName);
121 PropertyHandler *addFunction(const std::string &fnName);
122
124 virtual void removeFunction(PropertyHandler *handler);
125
127 std::shared_ptr<Mantid::API::CompositeFunction> compositeFunction() const { return m_compositeFunction; }
128
130 Mantid::API::IFunction_sptr getFittingFunction() const;
132 Mantid::API::IFunction_sptr getFunctionAtIndex(std::size_t const &index) const;
133
135 const std::string &defaultFunctionType() const;
137 void setDefaultFunctionType(const std::string &fnType);
139 std::string defaultPeakType();
141 void setDefaultPeakType(const std::string &fnType);
143 const std::string &defaultBackgroundType() const;
145 void setDefaultBackgroundType(const std::string &fnType);
146
148 std::shared_ptr<Mantid::API::Workspace> getWorkspace() const;
150 std::string workspaceName() const;
152 virtual void setWorkspaceName(const QString &wsName) override;
154 int workspaceIndex() const;
156 void setWorkspaceIndex(int i) override;
158 virtual std::string outputName() const;
160 void setOutputName(const std::string & /*name*/);
162 std::string minimizer(bool withProperties = false) const;
164 bool ignoreInvalidData() const;
166 void setIgnoreInvalidData(bool on);
168 std::string costFunction() const;
170 bool convolveMembers() const;
172 bool isHistogramFit() const;
174 void normaliseData(bool on) { m_shouldBeNormalised = on; }
176 int maxIterations() const;
178 int getPeakRadius() const;
180 std::string getExcludeRange() const;
182 QVector<double> getXRange();
183
185 std::string getFunctionString() const;
187 double startX() const;
189 void setStartX(double start) override;
191 double endX() const;
193 void setEndX(double end) override;
195 void setXRange(double start, double end);
197 QString getXColumnName() const;
199 QString getYColumnName() const;
201 QString getErrColumnName() const;
202
204 const QStringList &registeredFunctions() const { return m_registeredFunctions; }
206 const QStringList &registeredPeaks() const { return m_registeredPeaks; }
208 const QStringList &registeredBackgrounds() const { return m_registeredBackgrounds; }
210 const QStringList &registeredOthers() const { return m_registeredOther; }
211
213 bool isUndoEnabled() const;
215 bool isFitEnabled() const;
216
218 virtual void setFitEnabled(bool enable);
219
221 void setTip(const QString &txt);
222
224 void setTextPlotGuess(const QString &text);
225
227 QString getTieString() const;
228
230 QString getConstraintsString() const;
231
232 // send parameterChanged signal
233 void sendParameterChanged(const Mantid::API::IFunction *f) { emit parameterChanged(f); }
234
235 // send parameterChanged signal
236 void sendParameterChanged(const QString &prefix) { emit changedParameterOf(prefix); }
237
239 void addAutoBackground();
240 bool isAutoBack() const { return m_autoBackground != nullptr; }
241 void setAutoBackgroundName(const QString &aName);
242 void refitAutoBackground();
243 QString getAutoBackgroundString() const { return m_autoBgName + " " + m_autoBgAttributes; }
244
246 int getDecimals() const { return m_decimals; }
247 void setDecimals(int d);
248
250 bool plotDiff() const;
252 bool plotCompositeMembers() const;
253
255 bool rawData() const override;
256
257 void setADSObserveEnabled(bool enabled);
258
259 void postDeleteHandle(const std::string &wsName) override;
260 void renameHandle(const std::string &oldName, const std::string &newName) override;
261 void addHandle(const std::string &wsName, const std::shared_ptr<Mantid::API::Workspace> &ws) override;
262
263 // Remove Workspace
264 void removeWorkspace(const std::string &wsName);
265 void removeWorkspaceAndSpectra(const std::string &wsName);
266
268 void finishHandle(const Mantid::API::IAlgorithm *alg) override;
269
272 const QStringList &getWorkspaceNames();
273
276 void allowSequentialFits(bool allow) override;
277
280 QMenu *getFitMenu() const { return m_fitMenu; }
281
284 QListWidget *getWorkspaceList() const { return m_wsListWidget; }
285
287 void addFitResultWorkspacesToTableWidget();
288
289 // Methods intended for testing only
290
291 int sizeOfFunctionsGroup() const;
292
293 // Methods intended for interfacing with the workbench fitting tools
294
295 void addAllowedSpectra(const QString &wsName, const QList<int> &wsIndices);
296 void addAllowedTableWorkspace(const QString &wsName);
297 QString addFunction(const QString &fnName);
298 PropertyHandler *getPeakHandler(const QString &prefix);
299 void setPeakCentreOf(const QString &prefix, double value);
300 double getPeakCentreOf(const QString &prefix);
301 void setPeakHeightOf(const QString &prefix, double value);
302 double getPeakHeightOf(const QString &prefix);
303 void setPeakFwhmOf(const QString &prefix, double value);
304 double getPeakFwhmOf(const QString &prefix);
305 std::string getWidthParameterNameOf(const QString &prefix);
306 std::string getCentreParameterNameOf(const QString &prefix);
307 bool isParameterExplicitlySetOf(const QString &prefix, const std::string &param);
308 QStringList getPeakPrefixes() const;
309 void findPeaks(const std::unique_ptr<FindPeakStrategyGeneric> findPeakStrategy);
310 bool createAndAddFunction(const Mantid::API::MatrixWorkspace_sptr inputWS, const size_t peakIndex,
311 const std::unique_ptr<FindPeakStrategyGeneric> &findPeakStrategy);
312
313 // Emits a signal for when the sequential fit has finished
314
315 void sequentialFitFinished() { emit sequentialFitDone(); }
316
317public slots:
318 virtual void fit();
319 virtual void toggleSettingsBrowserVisible();
320 virtual void removePropertiesFromSettingsBrowser(const QStringList &propsToRemove);
321 virtual void toggleWsListVisible();
322 virtual void sequentialFit();
323 void undoFit();
324 virtual void clear();
325 void clearBrowser();
326 void setPeakToolOn(bool on);
327 virtual void executeFitMenu(const QString & /*item*/);
328 void executeDisplayMenu(const QString & /*item*/);
329 void executeSetupMenu(const QString & /*item*/);
330 void executePeakFindingAlgMenu(const QString & /*item*/);
331 void executeSetupManageMenu(const QString & /*item*/);
332 void workspaceDoubleClicked(QListWidgetItem *item);
333 void executeCustomSetupRemove(const QString &name);
334 void executeClearCustomSetups();
335
336signals:
337 void currentChanged() const;
339 void algorithmFinished(const QString & /*_t1*/);
341 void algorithmStarted(const QString & /*_t1*/);
344 void workspaceNameChanged(const QString & /*_t1*/);
345 void sequentialFitDone() const;
346
347 void wsChangePPAssign(const QString & /*_t1*/);
349
350 void startXChanged(double /*_t1*/);
351 void endXChanged(double /*_t1*/);
352 void xRangeChanged(double /*_t1*/, double /*_t2*/);
354 void changedParameterOf(const QString &prefix);
356 void plotGuess();
360 void changeWindowTitle(const QString & /*_t1*/);
363
364 void executeFit(QString /*_t1*/, QHash<QString, QString> /*_t2*/, Mantid::API::AlgorithmObserver * /*_t3*/);
366
369 void fittingDone(const QString & /*_t1*/);
371 void errorsEnabled(bool enabled);
372 void fitUndone();
373 void functionLoaded(const QString & /*_t1*/);
374 void fitResultsChanged(const QString &status);
375 void workspaceClicked(const QString &wsName);
376 void itemDoubleClicked(QListWidgetItem *item);
377
378protected slots:
380 virtual void populateFunctionNames();
382 virtual void boolChanged(QtProperty *prop);
383
384 virtual void enumChanged(QtProperty *prop);
385
386 virtual void intChanged(QtProperty *prop);
387
388 virtual void doubleChanged(QtProperty *prop);
389
390 void enactAttributeChange(QtProperty *prop, PropertyHandler *h, const bool vectorAttribute = false);
391
392private slots:
394 void parameterChanged(QtProperty *prop);
395 void stringChanged(QtProperty *prop);
396 void filenameChanged(QtProperty *prop);
397 void columnChanged(QtProperty *prop);
398 void currentItemChanged(QtBrowserItem * /*current*/);
399 void vectorDoubleChanged(QtProperty *prop);
400 void vectorSizeChanged(QtProperty *prop);
401 void addTie();
402 void addTieToFunction();
403 void addFixTie();
404 void deleteTie();
405 void addLowerBound10();
406 void addLowerBound50();
407 void addLowerBound();
408 void addConstraint(int f, bool lo, bool up);
409 void addUpperBound10();
410 void addUpperBound50();
411 void addUpperBound();
412 void addBothBounds10();
413 void addBothBounds50();
414 void addBothBounds();
415 void removeBounds();
416 void plotGuessCurrent();
417 void plotGuessAll();
418 void removeGuessCurrent();
419 void removeGuessAll();
420 void plotOrRemoveGuessAll();
421 void clearAllPlots();
422 void saveFunction();
423 void loadFunction();
424 void loadFunctionFromString();
425 void acceptFit();
426 void closeFit();
427 void copy();
428 void paste();
429 void reset();
430 void functionHelp();
431 void browserHelp();
432
433 void popupMenu(const QPoint & /*unused*/);
434 /* Context menu slots */
435 void addFunction();
436 void deleteFunction();
437 void setupMultifit();
438
440 void processMultiBGResults();
441
442 void executeCustomSetupLoad(const QString &name);
443
445 void updateStructureTooltips();
447 void showFitResultStatus(const QString &status);
449 void clearFitResultStatus();
450
451public: // functions declared public for testing
452 QString getOldExpressionAsString(const QString &parameterName) const;
454 void createCompositeFunction(const QString &str = "");
455
456protected:
457 void modifyFitMenu(QAction *fitAction, bool enabled);
458 virtual void populateFitMenuButton(QSignalMapper *fitMapper, QMenu *fitMenu);
459 bool getShouldBeNormalised() { return m_shouldBeNormalised; };
461 void showEvent(QShowEvent *e) override;
463 void hideEvent(QHideEvent *e) override;
465 void populateWorkspaceNames();
467 void createEditors(QWidget *w);
469 void initLayout(QWidget *w);
471 void initBasicLayout(QWidget *w);
473 void updateDecimals();
475 void setWorkspace(const Mantid::API::IFunction_sptr &function) const;
477 void setWorkspaceProperties();
479 virtual void addWorkspaceIndexToBrowser();
481 void updateBrowserFromFitResults(const Mantid::API::IFunction_sptr &finalFunction);
483 QtProperty *addDoubleProperty(const QString &name, QtDoublePropertyManager *manager = nullptr) const;
485 void minimizerChanged();
487 void doFit(int maxIterations);
489 Mantid::API::IFunction_sptr tryCreateFitFunction(const QString &str);
491 void createCompositeFunction(const Mantid::API::IFunction_sptr &func);
492
494 QtGroupPropertyManager *m_groupManager;
495 QtDoublePropertyManager *m_doubleManager;
496 QtEnumPropertyManager *m_enumManager;
497 QtIntPropertyManager *m_intManager;
498 QtBoolPropertyManager *m_boolManager;
499 QtStringPropertyManager *m_stringManager;
500 QtStringPropertyManager *m_filenameManager;
501 QtStringPropertyManager *m_formulaManager;
502 QtEnumPropertyManager *m_columnManager;
503 QtGroupPropertyManager *m_vectorManager;
504 QtIntPropertyManager *m_vectorSizeManager;
505 QtDoublePropertyManager *m_vectorDoubleManager;
506 ParameterPropertyManager *m_parameterManager;
507
508 QtProperty *m_workspace;
509 QtProperty *m_workspaceIndex;
510 QtProperty *m_startX;
511 QtProperty *m_endX;
512 QtProperty *m_output;
513 QtProperty *m_minimizer;
515 QtProperty *m_costFunction;
516 QtProperty *m_maxIterations;
517 QtProperty *m_peakRadius;
518 QtProperty *m_plotDiff;
519 QtProperty *m_excludeRange;
521 QtProperty *m_convolveMembers;
522 QtProperty *m_rawData;
523 QtProperty *m_xColumn;
524 QtProperty *m_yColumn;
525 QtProperty *m_errColumn;
526 QtProperty *m_showParamErrors;
527 QtProperty *m_evaluationType;
529
531 std::shared_ptr<Mantid::API::CompositeFunction> m_compositeFunction;
532
533 QtTreePropertyBrowser *m_browser;
534
539
541 QtBrowserItem *m_functionsGroup;
543 QtBrowserItem *m_settingsGroup;
545 QtBrowserItem *m_customSettingsGroup;
546
553
555 mutable QStringList m_registeredFunctions;
557 mutable QStringList m_registeredPeaks;
559 mutable QStringList m_registeredBackgrounds;
561 mutable QStringList m_registeredOther;
563 mutable QStringList m_minimizers;
565 mutable QStringList m_workspaceNames;
567 mutable QStringList m_costFunctions;
569 mutable QStringList m_evaluationTypes;
570
572 std::vector<double> m_initialParameters;
573
574private:
576 QPushButton *createFitMenuButton(QWidget *w);
578 virtual bool isWorkspaceValid(Mantid::API::Workspace_sptr /*ws*/) const;
580 QtBrowserItem *findItem(QtBrowserItem *parent, QtProperty *prop) const;
581
583 void disableUndo();
585 QtProperty *addStringProperty(const QString &name) const;
586 void setStringPropertyValue(QtProperty *prop, const QString &value) const;
587 QString getStringPropertyValue(QtProperty *prop) const;
589 QtProperty *addStringListProperty(const QString &name, const std::vector<std::string> &allowed_values) const;
591 void checkFunction();
593 int getAllowedIndex(int currentIndex) const;
594
595 void setCurrentFunction(const Mantid::API::IFunction_const_sptr &f) const;
596
598 virtual void workspaceChange(const QString &wsName);
599
601 void hasConstraints(QtProperty *parProp, bool &hasTie, bool &hasFix, bool &hasBounds) const;
603 QtProperty *getTieProperty(QtProperty *parProp) const;
604
606 void handleFactoryUpdate(Mantid::API::FunctionFactoryUpdateNotification_ptr /*notice*/);
609
611 // void validateGroupMember();
612
614 QSignalMapper *m_fitMapper;
615 QMenu *m_fitMenu;
620
624 void updateSetupMenus();
625
627 QLabel *m_tip;
629 QLabel *m_status;
630
631 // The widget for choosing the fit function.
633 // The tree widget containing the fit functions.
634 QTreeWidget *m_fitTree;
635
636 //
637 QListWidget *m_wsListWidget;
639
643 QMap<QString, QtStringPropertyManager *> m_stringManagers;
644
646
648 mutable QStringList m_dataTypes;
649
651 std::string m_defaultFunction;
653 std::string m_defaultPeak;
656
659
662
665
671
674
677
679 QObject *m_mantidui;
680
683
686
687 // Keep a history of the parameters used to run the Fit algorithm
690
695 QMap<QString, QList<int>> m_allowedSpectra;
700
701 friend class PropertyHandler;
703 friend class SetAttribute;
706};
707
708} // namespace MantidWidgets
709} // namespace MantidQt
std::string name
Definition Run.cpp:60
#define EXPORT_OPT_MANTIDQT_COMMON
Definition DllOption.h:15
double value
The value of the point.
Definition FitMW.cpp:51
double height
Definition GetAllEi.cpp:155
std::map< DeltaEMode::Type, std::string > index
int count
counter
Definition Matrix.cpp:37
Observes AnalysisDataService notifications: add,replace,delete.
Attribute visitor to create a QtProperty.
Class FitPropertyBrowser implements QtPropertyBrowser to display and control fitting function paramet...
QStringList m_dataTypes
A list of available data types.
int m_decimals
Number of decimal places in double properties.
bool m_shouldBeNormalised
Should the data be normalised before fitting?
QMenu * getFitMenu() const
Return the Fit menu.
void normaliseData(bool on)
Set if the data must be normalised before fitting.
void fittingDone(const QString &)
signal which can optionally be caught for customization after a fit has been done
std::shared_ptr< Mantid::API::CompositeFunction > compositeFunction() const
Get Composite Function.
bool m_hideWsListWidget
bool to display ws list or not
const QStringList & registeredOthers() const
Return a list of registered other functions.
void sendParameterChanged(const Mantid::API::IFunction *f)
QStringList m_registeredBackgrounds
A list of registered backgrounds.
void changedParameterOf(const QString &prefix)
QStringList m_registeredOther
A list of registered functions that are neither peaks nor backgrounds.
std::vector< double > m_initialParameters
To keep a copy of the initial parameters in case for undo fit.
QtGroupPropertyManager * m_groupManager
Property managers:
int m_oldWorkspaceIndex
Store workspace index to revert to in case validation fails.
QStringList m_registeredPeaks
A list of registered peaks.
QString m_allowedTableWorkspace
If set it contains the table workspace name to be fitted in this browser:
bool m_auto_back
If true background function will be included automatically.
int getDecimals() const
Number of decimal places in double properties.
std::string m_defaultFunction
Default function name.
void workspaceClicked(const QString &wsName)
const QStringList & registeredBackgrounds() const
Return a list of registered backgrounds.
QListWidget * getWorkspaceList() const
Return the Fit menu.
void executeFit(QString, QHash< QString, QString >, Mantid::API::AlgorithmObserver *)
QtBrowserItem * m_settingsGroup
Group for input/output settings.
QObject * m_mantidui
holds effectively a MantidUI for connecting
QString getTieString() const
Creates the "Ties" property value for the Fit algorithm.
QStringList m_workspaceNames
A list of available workspaces.
void removePlotSignal(MantidQt::MantidWidgets::PropertyHandler *)
QString getConstraintsString() const
Creates the "Constraints" property value for the Fit algorithm.
bool m_peakToolOn
Shows if the PeakPickerTool is on.
Poco::NObserver< FitPropertyBrowser, Mantid::API::FunctionFactoryUpdateNotification > m_updateObserver
Observes algorithm factory update notifications.
bool m_changeSlotsEnabled
If false the change-slots (such as enumChanged(), doubleChanged()) are disabled.
void parameterChanged(const Mantid::API::IFunction *)
QMap< QString, QtStringPropertyManager * > m_stringManagers
String property managers for special case attributes such as Filename or Formula <attribute_name,...
QtBrowserItem * m_functionsGroup
Group for functions.
std::string m_defaultBackground
Default background name.
QSignalMapper * m_fitMapper
Make sure m_groupMember belongs to the group.
void fitResultsChanged(const QString &status)
QString m_autoBgName
Name of the autobackground function.
QStringList m_evaluationTypes
A list of possible function evaluation types.
std::string m_storedWorkspaceName
store current workspace name
QMap< QString, QList< int > > m_allowedSpectra
If non-empty it contains references to the spectra allowed to be fitted in this browser: keys are wor...
const QStringList & registeredPeaks() const
Return a list of registered peaks.
bool m_guessOutputName
if true the output name will be guessed every time workspace name is changeed
QStringList m_minimizers
A list of available minimizers.
QString m_autoBgAttributes
List of attributes of the autobackground function as name=value pairs separated by spaces.
QStringList m_registeredFunctions
A list of registered functions.
const QStringList & registeredFunctions() const
Return a list of registered functions.
PropertyHandler * m_autoBackground
The autobackground handler.
std::shared_ptr< Mantid::API::CompositeFunction > m_compositeFunction
A copy of the edited function.
QStringList m_costFunctions
A list of available cost functions.
QtBrowserItem * m_customSettingsGroup
Group for custom options available on muon analysis widget.
void itemDoubleClicked(QListWidgetItem *item)
IWorkspaceFitControl: set data to fit for a fit property browser.
Helps display and edit functions in FitPropertyBrowser.
Select a function type out of a list of available ones.
This is a dialog for doing sequential fit.
Visitor setting new attribute value.
Visitor setting new attribute value.
Observes Algorithm notifications: start,progress,finish,error.
IAlgorithm is the interface implemented by the Algorithm base class.
Definition IAlgorithm.h:45
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...
const Poco::AutoPtr< FunctionFactoryUpdateNotification > & FunctionFactoryUpdateNotification_ptr
Convenient typedef for an UpdateNotification AutoPtr.
std::shared_ptr< Workspace > Workspace_sptr
shared pointer to Mantid::API::Workspace
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
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class