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;
76
77 // delete copy operations - Poco::NObserver contains std::atomic which is not copyable
80
82 PropertyHandler *getHandler() const;
84 virtual void init();
85
87 double centre() const;
89 void setCentre(double value);
91 double height() const;
93 void setHeight(double value);
95 double fwhm() const;
97 void setFwhm(double value);
99 int count() const;
101 bool isPeak() const;
103 PropertyHandler *currentHandler() const;
105 void setCurrentFunction(PropertyHandler *h) const;
107 std::shared_ptr<const Mantid::API::IFunction> theFunction() const;
109 void updateParameters();
111 void updateAttributes();
113 QList<double> getParameterValues() const;
115 QStringList getParameterNames() const;
116 // Get parameters used to run the Fit algorithm
117 const std::string &getFitAlgorithmParameters() const;
118 // Get the status string returned from Fit
119 const std::string &getFitAlgorithmOutputStatus() const;
120
122 void loadFunction(const QString &funcString);
124 void saveFunction(const QString &fnName);
126 PropertyHandler *addFunction(const std::string &fnName);
127
129 virtual void removeFunction(PropertyHandler *handler);
130
132 std::shared_ptr<Mantid::API::CompositeFunction> compositeFunction() const { return m_compositeFunction; }
133
135 Mantid::API::IFunction_sptr getFittingFunction() const;
137 Mantid::API::IFunction_sptr getFunctionAtIndex(std::size_t const &index) const;
138
140 const std::string &defaultFunctionType() const;
142 void setDefaultFunctionType(const std::string &fnType);
144 std::string defaultPeakType();
146 void setDefaultPeakType(const std::string &fnType);
148 const std::string &defaultBackgroundType() const;
150 void setDefaultBackgroundType(const std::string &fnType);
151
153 std::shared_ptr<Mantid::API::Workspace> getWorkspace() const;
155 std::string workspaceName() const;
157 virtual void setWorkspaceName(const QString &wsName) override;
159 int workspaceIndex() const;
161 void setWorkspaceIndex(int i) override;
163 virtual std::string outputName() const;
165 void setOutputName(const std::string & /*name*/);
167 std::string minimizer(bool withProperties = false) const;
169 bool ignoreInvalidData() const;
171 void setIgnoreInvalidData(bool on);
173 std::string costFunction() const;
175 bool convolveMembers() const;
177 bool isHistogramFit() const;
179 void normaliseData(bool on) { m_shouldBeNormalised = on; }
181 int maxIterations() const;
183 int getPeakRadius() const;
185 std::string getExcludeRange() const;
187 QVector<double> getXRange();
188
190 std::string getFunctionString() const;
192 double startX() const;
194 void setStartX(double start) override;
196 double endX() const;
198 void setEndX(double end) override;
200 void setXRange(double start, double end);
202 QString getXColumnName() const;
204 QString getYColumnName() const;
206 QString getErrColumnName() const;
207
209 const QStringList &registeredFunctions() const { return m_registeredFunctions; }
211 const QStringList &registeredPeaks() const { return m_registeredPeaks; }
213 const QStringList &registeredBackgrounds() const { return m_registeredBackgrounds; }
215 const QStringList &registeredOthers() const { return m_registeredOther; }
216
218 bool isUndoEnabled() const;
220 bool isFitEnabled() const;
221
223 virtual void setFitEnabled(bool enable);
224
226 void setTip(const QString &txt);
227
229 void setTextPlotGuess(const QString &text);
230
232 QString getTieString() const;
233
235 QString getConstraintsString() const;
236
237 // send parameterChanged signal
238 void sendParameterChanged(const Mantid::API::IFunction *f) { emit parameterChanged(f); }
239
240 // send parameterChanged signal
241 void sendParameterChanged(const QString &prefix) { emit changedParameterOf(prefix); }
242
244 void addAutoBackground();
245 bool isAutoBack() const { return m_autoBackground != nullptr; }
246 void setAutoBackgroundName(const QString &aName);
247 void refitAutoBackground();
248 QString getAutoBackgroundString() const { return m_autoBgName + " " + m_autoBgAttributes; }
249
251 int getDecimals() const { return m_decimals; }
252 void setDecimals(int d);
253
255 bool plotDiff() const;
257 bool plotCompositeMembers() const;
258
260 bool rawData() const override;
261
262 void setADSObserveEnabled(bool enabled);
263
264 void postDeleteHandle(const std::string &wsName) override;
265 void renameHandle(const std::string &oldName, const std::string &newName) override;
266 void addHandle(const std::string &wsName, const std::shared_ptr<Mantid::API::Workspace> &ws) override;
267
268 // Remove Workspace
269 void removeWorkspace(const std::string &wsName);
270 void removeWorkspaceAndSpectra(const std::string &wsName);
271
273 void finishHandle(const Mantid::API::IAlgorithm *alg) override;
274
277 const QStringList &getWorkspaceNames();
278
281 void allowSequentialFits(bool allow) override;
282
285 QMenu *getFitMenu() const { return m_fitMenu; }
286
289 QListWidget *getWorkspaceList() const { return m_wsListWidget; }
290
292 void addFitResultWorkspacesToTableWidget();
293
294 // Methods intended for testing only
295
296 int sizeOfFunctionsGroup() const;
297
298 // Methods intended for interfacing with the workbench fitting tools
299
300 void addAllowedSpectra(const QString &wsName, const QList<int> &wsIndices);
301 void addAllowedTableWorkspace(const QString &wsName);
302 QString addFunction(const QString &fnName);
303 PropertyHandler *getPeakHandler(const QString &prefix);
304 void setPeakCentreOf(const QString &prefix, double value);
305 double getPeakCentreOf(const QString &prefix);
306 void setPeakHeightOf(const QString &prefix, double value);
307 double getPeakHeightOf(const QString &prefix);
308 void setPeakFwhmOf(const QString &prefix, double value);
309 double getPeakFwhmOf(const QString &prefix);
310 std::string getWidthParameterNameOf(const QString &prefix);
311 std::string getCentreParameterNameOf(const QString &prefix);
312 bool isParameterExplicitlySetOf(const QString &prefix, const std::string &param);
313 QStringList getPeakPrefixes() const;
314 void findPeaks(const std::unique_ptr<FindPeakStrategyGeneric> findPeakStrategy);
315 bool createAndAddFunction(const Mantid::API::MatrixWorkspace_sptr inputWS, const size_t peakIndex,
316 const std::unique_ptr<FindPeakStrategyGeneric> &findPeakStrategy);
317
318 // Emits a signal for when the sequential fit has finished
319
320 void sequentialFitFinished() { emit sequentialFitDone(); }
321
322public slots:
323 virtual void fit();
324 virtual void toggleSettingsBrowserVisible();
325 virtual void removePropertiesFromSettingsBrowser(const QStringList &propsToRemove);
326 virtual void toggleWsListVisible();
327 virtual void sequentialFit();
328 void undoFit();
329 virtual void clear();
330 void clearBrowser();
331 void setPeakToolOn(bool on);
332 virtual void executeFitMenu(const QString & /*item*/);
333 void executeDisplayMenu(const QString & /*item*/);
334 void executeSetupMenu(const QString & /*item*/);
335 void executePeakFindingAlgMenu(const QString & /*item*/);
336 void executeSetupManageMenu(const QString & /*item*/);
337 void workspaceDoubleClicked(QListWidgetItem *item);
338 void executeCustomSetupRemove(const QString &name);
339 void executeClearCustomSetups();
340
341signals:
342 void currentChanged() const;
344 void algorithmFinished(const QString & /*_t1*/);
346 void algorithmStarted(const QString & /*_t1*/);
349 void workspaceNameChanged(const QString & /*_t1*/);
350 void sequentialFitDone() const;
351
352 void wsChangePPAssign(const QString & /*_t1*/);
354
355 void startXChanged(double /*_t1*/);
356 void endXChanged(double /*_t1*/);
357 void xRangeChanged(double /*_t1*/, double /*_t2*/);
359 void changedParameterOf(const QString &prefix);
361 void plotGuess();
365 void changeWindowTitle(const QString & /*_t1*/);
368
369 void executeFit(QString /*_t1*/, QHash<QString, QString> /*_t2*/, Mantid::API::AlgorithmObserver * /*_t3*/);
371
374 void fittingDone(const QString & /*_t1*/);
376 void errorsEnabled(bool enabled);
377 void fitUndone();
378 void functionLoaded(const QString & /*_t1*/);
379 void fitResultsChanged(const QString &status);
380 void workspaceClicked(const QString &wsName);
381 void itemDoubleClicked(QListWidgetItem *item);
382
383protected slots:
385 virtual void populateFunctionNames();
387 virtual void boolChanged(QtProperty *prop);
388
389 virtual void enumChanged(QtProperty *prop);
390
391 virtual void intChanged(QtProperty *prop);
392
393 virtual void doubleChanged(QtProperty *prop);
394
395 void enactAttributeChange(QtProperty *prop, PropertyHandler *h, const bool vectorAttribute = false);
396
397private slots:
399 void parameterChanged(QtProperty *prop);
400 void stringChanged(QtProperty *prop);
401 void filenameChanged(QtProperty *prop);
402 void columnChanged(QtProperty *prop);
403 void currentItemChanged(QtBrowserItem * /*current*/);
404 void vectorDoubleChanged(QtProperty *prop);
405 void vectorSizeChanged(QtProperty *prop);
406 void addTie();
407 void addTieToFunction();
408 void addFixTie();
409 void deleteTie();
410 void addLowerBound10();
411 void addLowerBound50();
412 void addLowerBound();
413 void addConstraint(int f, bool lo, bool up);
414 void addUpperBound10();
415 void addUpperBound50();
416 void addUpperBound();
417 void addBothBounds10();
418 void addBothBounds50();
419 void addBothBounds();
420 void removeBounds();
421 void plotGuessCurrent();
422 void plotGuessAll();
423 void removeGuessCurrent();
424 void removeGuessAll();
425 void plotOrRemoveGuessAll();
426 void clearAllPlots();
427 void saveFunction();
428 void loadFunction();
429 void loadFunctionFromString();
430 void acceptFit();
431 void closeFit();
432 void copy();
433 void paste();
434 void reset();
435 void functionHelp();
436 void browserHelp();
437
438 void popupMenu(const QPoint & /*unused*/);
439 /* Context menu slots */
440 void addFunction();
441 void deleteFunction();
442 void setupMultifit();
443
445 void processMultiBGResults();
446
447 void executeCustomSetupLoad(const QString &name);
448
450 void updateStructureTooltips();
452 void showFitResultStatus(const QString &status);
454 void clearFitResultStatus();
455
456public: // functions declared public for testing
457 QString getOldExpressionAsString(const QString &parameterName) const;
459 void createCompositeFunction(const QString &str = "");
460
461protected:
462 void modifyFitMenu(QAction *fitAction, bool enabled);
463 virtual void populateFitMenuButton(QSignalMapper *fitMapper, QMenu *fitMenu);
464 bool getShouldBeNormalised() { return m_shouldBeNormalised; };
466 void showEvent(QShowEvent *e) override;
468 void hideEvent(QHideEvent *e) override;
470 void populateWorkspaceNames();
472 void createEditors(QWidget *w);
474 void initLayout(QWidget *w);
476 void initBasicLayout(QWidget *w);
478 void updateDecimals();
480 void setWorkspace(const Mantid::API::IFunction_sptr &function) const;
482 void setWorkspaceProperties();
484 virtual void addWorkspaceIndexToBrowser();
486 void updateBrowserFromFitResults(const Mantid::API::IFunction_sptr &finalFunction);
488 QtProperty *addDoubleProperty(const QString &name, QtDoublePropertyManager *manager = nullptr) const;
490 void minimizerChanged();
492 void doFit(int maxIterations);
494 Mantid::API::IFunction_sptr tryCreateFitFunction(const QString &str);
496 void createCompositeFunction(const Mantid::API::IFunction_sptr &func);
497
499 QtGroupPropertyManager *m_groupManager;
500 QtDoublePropertyManager *m_doubleManager;
501 QtEnumPropertyManager *m_enumManager;
502 QtIntPropertyManager *m_intManager;
503 QtBoolPropertyManager *m_boolManager;
504 QtStringPropertyManager *m_stringManager;
505 QtStringPropertyManager *m_filenameManager;
506 QtStringPropertyManager *m_formulaManager;
507 QtEnumPropertyManager *m_columnManager;
508 QtGroupPropertyManager *m_vectorManager;
509 QtIntPropertyManager *m_vectorSizeManager;
510 QtDoublePropertyManager *m_vectorDoubleManager;
511 ParameterPropertyManager *m_parameterManager;
512
513 QtProperty *m_workspace;
514 QtProperty *m_workspaceIndex;
515 QtProperty *m_startX;
516 QtProperty *m_endX;
517 QtProperty *m_output;
518 QtProperty *m_minimizer;
520 QtProperty *m_costFunction;
521 QtProperty *m_maxIterations;
522 QtProperty *m_peakRadius;
523 QtProperty *m_plotDiff;
524 QtProperty *m_excludeRange;
526 QtProperty *m_convolveMembers;
527 QtProperty *m_rawData;
528 QtProperty *m_xColumn;
529 QtProperty *m_yColumn;
530 QtProperty *m_errColumn;
531 QtProperty *m_showParamErrors;
532 QtProperty *m_evaluationType;
534
536 std::shared_ptr<Mantid::API::CompositeFunction> m_compositeFunction;
537
538 QtTreePropertyBrowser *m_browser;
539
544
546 QtBrowserItem *m_functionsGroup;
548 QtBrowserItem *m_settingsGroup;
550 QtBrowserItem *m_customSettingsGroup;
551
558
560 mutable QStringList m_registeredFunctions;
562 mutable QStringList m_registeredPeaks;
564 mutable QStringList m_registeredBackgrounds;
566 mutable QStringList m_registeredOther;
568 mutable QStringList m_minimizers;
570 mutable QStringList m_workspaceNames;
572 mutable QStringList m_costFunctions;
574 mutable QStringList m_evaluationTypes;
575
577 std::vector<double> m_initialParameters;
578
579private:
581 QPushButton *createFitMenuButton(QWidget *w);
583 virtual bool isWorkspaceValid(Mantid::API::Workspace_sptr /*ws*/) const;
585 QtBrowserItem *findItem(QtBrowserItem *parent, QtProperty *prop) const;
586
588 void disableUndo();
590 QtProperty *addStringProperty(const QString &name) const;
591 void setStringPropertyValue(QtProperty *prop, const QString &value) const;
592 QString getStringPropertyValue(QtProperty *prop) const;
594 QtProperty *addStringListProperty(const QString &name, const std::vector<std::string> &allowed_values) const;
596 void checkFunction();
598 int getAllowedIndex(int currentIndex) const;
599
600 void setCurrentFunction(const Mantid::API::IFunction_const_sptr &f) const;
601
603 virtual void workspaceChange(const QString &wsName);
604
606 void hasConstraints(QtProperty *parProp, bool &hasTie, bool &hasFix, bool &hasBounds) const;
608 QtProperty *getTieProperty(QtProperty *parProp) const;
609
611 void handleFactoryUpdate(Mantid::API::FunctionFactoryUpdateNotification_ptr /*notice*/);
614
616 // void validateGroupMember();
617
619 QSignalMapper *m_fitMapper;
620 QMenu *m_fitMenu;
625
629 void updateSetupMenus();
630
632 QLabel *m_tip;
634 QLabel *m_status;
635
636 // The widget for choosing the fit function.
638 // The tree widget containing the fit functions.
639 QTreeWidget *m_fitTree;
640
641 //
642 QListWidget *m_wsListWidget;
644
648 QMap<QString, QtStringPropertyManager *> m_stringManagers;
649
651
653 mutable QStringList m_dataTypes;
654
656 std::string m_defaultFunction;
658 std::string m_defaultPeak;
661
664
667
670
676
679
682
684 QObject *m_mantidui;
685
688
691
692 // Keep a history of the parameters used to run the Fit algorithm
695
700 QMap<QString, QList<int>> m_allowedSpectra;
705
706 friend class PropertyHandler;
708 friend class SetAttribute;
711};
712
713} // namespace MantidWidgets
714} // 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.
FitPropertyBrowser(const FitPropertyBrowser &)=delete
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
FitPropertyBrowser & operator=(const FitPropertyBrowser &)=delete
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