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"
26
27/* Forward declarations */
28
29class QtTreePropertyBrowser;
30class QtGroupPropertyManager;
31class QtDoublePropertyManager;
32class QtIntPropertyManager;
33class QtBoolPropertyManager;
34class QtStringPropertyManager;
35class QtEnumPropertyManager;
36class ParameterPropertyManager;
37
38class QtProperty;
39class QtBrowserItem;
40
41class QAction;
42class QComboBox;
43class QLabel;
44class QLineEdit;
45class QListWidget;
46class QListWidgetItem;
47class QMenu;
48class QPushButton;
49class QSignalMapper;
50class QTreeWidget;
51class QVBoxLayout;
52
53namespace MantidQt {
54namespace MantidWidgets {
55
56class PropertyHandler;
57class SelectFunctionDialog;
69 Q_OBJECT
70public:
72 FitPropertyBrowser(QWidget *parent = nullptr, QObject *mantidui = nullptr);
74 ~FitPropertyBrowser() override;
76 PropertyHandler *getHandler() const;
78 virtual void init();
79
81 double centre() const;
83 void setCentre(double value);
85 double height() const;
87 void setHeight(double value);
89 double fwhm() const;
91 void setFwhm(double value);
93 int count() const;
95 bool isPeak() const;
97 PropertyHandler *currentHandler() const;
99 void setCurrentFunction(PropertyHandler *h) const;
101 std::shared_ptr<const Mantid::API::IFunction> theFunction() const;
103 void updateParameters();
105 void updateAttributes();
107 QList<double> getParameterValues() const;
109 QStringList getParameterNames() const;
110 // Get parameters used to run the Fit algorithm
111 std::string getFitAlgorithmParameters() const;
112 // Get the status string returned from Fit
113 std::string getFitAlgorithmOutputStatus() const;
114
116 void loadFunction(const QString &funcString);
118 void saveFunction(const QString &fnName);
120 PropertyHandler *addFunction(const std::string &fnName);
121
123 virtual void removeFunction(PropertyHandler *handler);
124
126 std::shared_ptr<Mantid::API::CompositeFunction> compositeFunction() const { return m_compositeFunction; }
127
129 Mantid::API::IFunction_sptr getFittingFunction() const;
131 Mantid::API::IFunction_sptr getFunctionAtIndex(std::size_t const &index) const;
132
134 std::string defaultFunctionType() const;
136 void setDefaultFunctionType(const std::string &fnType);
138 std::string defaultPeakType();
140 void setDefaultPeakType(const std::string &fnType);
142 std::string defaultBackgroundType() const;
144 void setDefaultBackgroundType(const std::string &fnType);
145
147 std::shared_ptr<Mantid::API::Workspace> getWorkspace() const;
149 std::string workspaceName() const;
151 virtual void setWorkspaceName(const QString &wsName) override;
153 int workspaceIndex() const;
155 void setWorkspaceIndex(int i) override;
157 virtual std::string outputName() const;
159 void setOutputName(const std::string & /*name*/);
161 std::string minimizer(bool withProperties = false) const;
163 bool ignoreInvalidData() const;
165 void setIgnoreInvalidData(bool on);
167 std::string costFunction() const;
169 bool convolveMembers() const;
171 bool isHistogramFit() const;
173 void normaliseData(bool on) { m_shouldBeNormalised = on; }
175 int maxIterations() const;
177 int getPeakRadius() const;
179 std::string getExcludeRange() const;
181 QVector<double> getXRange();
182
184 std::string getFunctionString() const;
186 double startX() const;
188 void setStartX(double start) override;
190 double endX() const;
192 void setEndX(double end) override;
194 void setXRange(double start, double end);
196 QString getXColumnName() const;
198 QString getYColumnName() const;
200 QString getErrColumnName() const;
201
203 const QStringList &registeredFunctions() const { return m_registeredFunctions; }
205 const QStringList &registeredPeaks() const { return m_registeredPeaks; }
207 const QStringList &registeredBackgrounds() const { return m_registeredBackgrounds; }
209 const QStringList &registeredOthers() const { return m_registeredOther; }
210
212 bool isUndoEnabled() const;
214 bool isFitEnabled() const;
215
217 virtual void setFitEnabled(bool enable);
218
220 void setTip(const QString &txt);
221
223 void setTextPlotGuess(const QString &text);
224
226 QString getTieString() const;
227
229 QString getConstraintsString() const;
230
231 // send parameterChanged signal
232 void sendParameterChanged(const Mantid::API::IFunction *f) { emit parameterChanged(f); }
233
234 // send parameterChanged signal
235 void sendParameterChanged(const QString &prefix) { emit changedParameterOf(prefix); }
236
238 void addAutoBackground();
239 bool isAutoBack() const { return m_autoBackground != nullptr; }
240 void setAutoBackgroundName(const QString &aName);
241 void refitAutoBackground();
242 QString getAutoBackgroundString() const { return m_autoBgName + " " + m_autoBgAttributes; }
243
245 int getDecimals() const { return m_decimals; }
246 void setDecimals(int d);
247
249 bool plotDiff() const;
251 bool plotCompositeMembers() const;
252
254 bool rawData() const override;
255
256 void setADSObserveEnabled(bool enabled);
257
258 void postDeleteHandle(const std::string &wsName) override;
259 void renameHandle(const std::string &oldName, const std::string &newName) override;
260 void addHandle(const std::string &wsName, const std::shared_ptr<Mantid::API::Workspace> &ws) override;
261
262 // Remove Workspace
263 void removeWorkspace(const std::string &wsName);
264 void removeWorkspaceAndSpectra(const std::string &wsName);
265
267 void finishHandle(const Mantid::API::IAlgorithm *alg) override;
268
271 QStringList getWorkspaceNames();
272
275 void allowSequentialFits(bool allow) override;
276
279 QMenu *getFitMenu() const { return m_fitMenu; }
280
283 QListWidget *getWorkspaceList() const { return m_wsListWidget; }
284
286 void addFitResultWorkspacesToTableWidget();
287
288 // Methods intended for testing only
289
290 int sizeOfFunctionsGroup() const;
291
292 // Methods intended for interfacing with the workbench fitting tools
293
294 void addAllowedSpectra(const QString &wsName, const QList<int> &wsIndices);
295 void addAllowedTableWorkspace(const QString &wsName);
296 QString addFunction(const QString &fnName);
297 PropertyHandler *getPeakHandler(const QString &prefix);
298 void setPeakCentreOf(const QString &prefix, double value);
299 double getPeakCentreOf(const QString &prefix);
300 void setPeakHeightOf(const QString &prefix, double value);
301 double getPeakHeightOf(const QString &prefix);
302 void setPeakFwhmOf(const QString &prefix, double value);
303 double getPeakFwhmOf(const QString &prefix);
304 std::string getWidthParameterNameOf(const QString &prefix);
305 std::string getCentreParameterNameOf(const QString &prefix);
306 bool isParameterExplicitlySetOf(const QString &prefix, const std::string &param);
307 QStringList getPeakPrefixes() const;
308
309 // Emits a signal for when the sequential fit has finished
310
311 void sequentialFitFinished() { emit sequentialFitDone(); }
312
313public slots:
314 virtual void fit();
315 virtual void toggleSettingsBrowserVisible();
316 virtual void removePropertiesFromSettingsBrowser(const QStringList &propsToRemove);
317 virtual void toggleWsListVisible();
318 virtual void sequentialFit();
319 void undoFit();
320 virtual void clear();
321 void clearBrowser();
322 void setPeakToolOn(bool on);
323 void findPeaks();
324 virtual void executeFitMenu(const QString & /*item*/);
325 void executeDisplayMenu(const QString & /*item*/);
326 void executeSetupMenu(const QString & /*item*/);
327 void executeSetupManageMenu(const QString & /*item*/);
328 void workspaceDoubleClicked(QListWidgetItem *item);
329 void executeCustomSetupRemove(const QString &name);
330 void executeClearCustomSetups();
331
332signals:
333 void currentChanged() const;
335 void algorithmFinished(const QString & /*_t1*/);
336 void algorithmStarted(const QString & /*_t1*/);
339 void workspaceNameChanged(const QString & /*_t1*/);
340 void sequentialFitDone() const;
341
342 void wsChangePPAssign(const QString & /*_t1*/);
344
345 void startXChanged(double /*_t1*/);
346 void endXChanged(double /*_t1*/);
347 void xRangeChanged(double /*_t1*/, double /*_t2*/);
349 void changedParameterOf(const QString &prefix);
351 void plotGuess();
355 void changeWindowTitle(const QString & /*_t1*/);
358
359 void executeFit(QString /*_t1*/, QHash<QString, QString> /*_t2*/, Mantid::API::AlgorithmObserver * /*_t3*/);
361
364 void fittingDone(const QString & /*_t1*/);
366 void errorsEnabled(bool enabled);
367 void fitUndone();
368 void functionLoaded(const QString & /*_t1*/);
369 void fitResultsChanged(const QString &status);
370 void workspaceClicked(const QString &wsName);
371 void itemDoubleClicked(QListWidgetItem *item);
372
373protected slots:
375 virtual void populateFunctionNames();
377 virtual void boolChanged(QtProperty *prop);
378
379 virtual void enumChanged(QtProperty *prop);
380
381 virtual void intChanged(QtProperty *prop);
382
383 virtual void doubleChanged(QtProperty *prop);
384
385 void enactAttributeChange(QtProperty *prop, PropertyHandler *h, const bool vectorAttribute = false);
386
387private slots:
389 void parameterChanged(QtProperty *prop);
390 void stringChanged(QtProperty *prop);
391 void filenameChanged(QtProperty *prop);
392 void columnChanged(QtProperty *prop);
393 void currentItemChanged(QtBrowserItem * /*current*/);
394 void vectorDoubleChanged(QtProperty *prop);
395 void vectorSizeChanged(QtProperty *prop);
396 void addTie();
397 void addTieToFunction();
398 void addFixTie();
399 void deleteTie();
400 void addLowerBound10();
401 void addLowerBound50();
402 void addLowerBound();
403 void addConstraint(int f, bool lo, bool up);
404 void addUpperBound10();
405 void addUpperBound50();
406 void addUpperBound();
407 void addBothBounds10();
408 void addBothBounds50();
409 void addBothBounds();
410 void removeBounds();
411 void plotGuessCurrent();
412 void plotGuessAll();
413 void removeGuessCurrent();
414 void removeGuessAll();
415 void plotOrRemoveGuessAll();
416 void clearAllPlots();
417 void saveFunction();
418 void loadFunction();
419 void loadFunctionFromString();
420 void acceptFit();
421 void closeFit();
422 void copy();
423 void paste();
424 void reset();
425 void functionHelp();
426 void browserHelp();
427
428 void popupMenu(const QPoint & /*unused*/);
429 /* Context menu slots */
430 void addFunction();
431 void deleteFunction();
432 void setupMultifit();
433
435 void processMultiBGResults();
436
437 void executeCustomSetupLoad(const QString &name);
438
440 void updateStructureTooltips();
442 void showFitResultStatus(const QString &status);
444 void clearFitResultStatus();
445
446protected:
447 void modifyFitMenu(QAction *fitAction, bool enabled);
448 virtual void populateFitMenuButton(QSignalMapper *fitMapper, QMenu *fitMenu);
449 bool getShouldBeNormalised() { return m_shouldBeNormalised; };
451 void showEvent(QShowEvent *e) override;
453 void hideEvent(QHideEvent *e) override;
455 void populateWorkspaceNames();
457 void createEditors(QWidget *w);
459 void initLayout(QWidget *w);
461 void initBasicLayout(QWidget *w);
463 void updateDecimals();
465 void setWorkspace(const Mantid::API::IFunction_sptr &function) const;
467 void setWorkspaceProperties();
469 virtual void addWorkspaceIndexToBrowser();
471 void updateBrowserFromFitResults(const Mantid::API::IFunction_sptr &finalFunction);
473 QtProperty *addDoubleProperty(const QString &name, QtDoublePropertyManager *manager = nullptr) const;
475 void minimizerChanged();
477 void doFit(int maxIterations);
479 void createCompositeFunction(const QString &str = "");
481 Mantid::API::IFunction_sptr tryCreateFitFunction(const QString &str);
483 void createCompositeFunction(const Mantid::API::IFunction_sptr &func);
484
486 QtGroupPropertyManager *m_groupManager;
487 QtDoublePropertyManager *m_doubleManager;
488 QtEnumPropertyManager *m_enumManager;
489 QtIntPropertyManager *m_intManager;
490 QtBoolPropertyManager *m_boolManager;
491 QtStringPropertyManager *m_stringManager;
492 QtStringPropertyManager *m_filenameManager;
493 QtStringPropertyManager *m_formulaManager;
494 QtEnumPropertyManager *m_columnManager;
495 QtGroupPropertyManager *m_vectorManager;
496 QtIntPropertyManager *m_vectorSizeManager;
497 QtDoublePropertyManager *m_vectorDoubleManager;
498 ParameterPropertyManager *m_parameterManager;
499
500 QtProperty *m_workspace;
501 QtProperty *m_workspaceIndex;
502 QtProperty *m_startX;
503 QtProperty *m_endX;
504 QtProperty *m_output;
505 QtProperty *m_minimizer;
507 QtProperty *m_costFunction;
508 QtProperty *m_maxIterations;
509 QtProperty *m_peakRadius;
510 QtProperty *m_plotDiff;
511 QtProperty *m_excludeRange;
513 QtProperty *m_convolveMembers;
514 QtProperty *m_rawData;
515 QtProperty *m_xColumn;
516 QtProperty *m_yColumn;
517 QtProperty *m_errColumn;
518 QtProperty *m_showParamErrors;
519 QtProperty *m_evaluationType;
521
523 std::shared_ptr<Mantid::API::CompositeFunction> m_compositeFunction;
524
525 QtTreePropertyBrowser *m_browser;
526
531
533 QtBrowserItem *m_functionsGroup;
535 QtBrowserItem *m_settingsGroup;
537 QtBrowserItem *m_customSettingsGroup;
538
545
547 mutable QStringList m_registeredFunctions;
549 mutable QStringList m_registeredPeaks;
551 mutable QStringList m_registeredBackgrounds;
553 mutable QStringList m_registeredOther;
555 mutable QStringList m_minimizers;
557 mutable QStringList m_workspaceNames;
559 mutable QStringList m_costFunctions;
561 mutable QStringList m_evaluationTypes;
562
564 std::vector<double> m_initialParameters;
565
566private:
568 QPushButton *createFitMenuButton(QWidget *w);
570 virtual bool isWorkspaceValid(Mantid::API::Workspace_sptr /*ws*/) const;
572 QtBrowserItem *findItem(QtBrowserItem *parent, QtProperty *prop) const;
573
575 void disableUndo();
577 QtProperty *addStringProperty(const QString &name) const;
578 void setStringPropertyValue(QtProperty *prop, const QString &value) const;
579 QString getStringPropertyValue(QtProperty *prop) const;
581 QtProperty *addStringListProperty(const QString &name, const std::vector<std::string> &allowed_values) const;
583 void checkFunction();
585 int getAllowedIndex(int currentIndex) const;
586
587 void setCurrentFunction(const Mantid::API::IFunction_const_sptr &f) const;
588
590 virtual void workspaceChange(const QString &wsName);
591
593 void hasConstraints(QtProperty *parProp, bool &hasTie, bool &hasBounds) const;
595 QtProperty *getTieProperty(QtProperty *parProp) const;
596
598 void handleFactoryUpdate(Mantid::API::FunctionFactoryUpdateNotification_ptr /*notice*/);
601
603 // void validateGroupMember();
604
606 QSignalMapper *m_fitMapper;
607 QMenu *m_fitMenu;
612
616 void updateSetupMenus();
617
619 QLabel *m_tip;
621 QLabel *m_status;
622
623 // The widget for choosing the fit function.
625 // The tree widget containing the fit functions.
626 QTreeWidget *m_fitTree;
627
628 //
629 QListWidget *m_wsListWidget;
631
635 QMap<QString, QtStringPropertyManager *> m_stringManagers;
636
638
640 mutable QStringList m_dataTypes;
641
643 std::string m_defaultFunction;
645 std::string m_defaultPeak;
648
651
654
657
663
666
669
671 QObject *m_mantidui;
672
675
678
679 // Keep a history of the parameters used to run the Fit algorithm
682
687 QMap<QString, QList<int>> m_allowedSpectra;
692
693 friend class PropertyHandler;
695 friend class SetAttribute;
698};
699
700} // namespace MantidWidgets
701} // namespace MantidQt
#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
Definition: DeltaEMode.cpp:19
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.
std::string m_defaultPeak
Default peak name.
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 sendParameterChanged(const QString &prefix)
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:163
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
Definition: Workspace_fwd.h:20
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