Mantid
Loading...
Searching...
No Matches
FunctionBrowser.cpp
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 +
10
18
19#include "MantidKernel/Logger.h"
20
21#include <QApplication>
22#include <QClipboard>
23#include <QHBoxLayout>
24#include <QMessageBox>
25
26#include <algorithm>
27#include <boost/lexical_cast.hpp>
28#include <utility>
29
30namespace {
31Mantid::Kernel::Logger g_log("Function Browser");
32} // namespace
33
35
36using namespace Mantid::API;
37using namespace Mantid::Kernel;
38
46FunctionBrowser::FunctionBrowser(QWidget *parent, bool multi, const std::vector<std::string> &categories)
47 : QWidget(parent) {
48 auto treeView = new FunctionTreeView(this, multi, categories);
49 m_presenter = std::make_unique<FunctionMultiDomainPresenter>(treeView);
50 QHBoxLayout *layout = new QHBoxLayout(this);
51 layout->setMargin(0);
52 layout->addWidget(treeView);
53 connect(m_presenter.get(), SIGNAL(functionStructureChanged()), this, SIGNAL(functionStructureChanged()));
54 connect(m_presenter.get(), SIGNAL(parameterChanged(std::string const &, std::string const &)), this,
55 SIGNAL(parameterChanged(std::string const &, std::string const &)));
56 connect(m_presenter.get(), SIGNAL(attributeChanged(std::string const &)), this,
57 SIGNAL(attributeChanged(std::string const &)));
58}
59
64
69
74void FunctionBrowser::setFunction(std::string const &funStr) { m_presenter->setFunctionString(funStr); }
75
80void FunctionBrowser::setFunction(IFunction_sptr fun) { m_presenter->setFunction(std::move(fun)); }
81
88 return m_presenter->getFunctionByIndex(index);
89}
95void FunctionBrowser::setParameter(std::string const &parameterName, double value) {
96 m_presenter->setParameter(parameterName, value);
97}
98
104void FunctionBrowser::setParameterError(std::string const &parameterName, double error) {
105 m_presenter->setParameterError(parameterName, error);
106}
107
112double FunctionBrowser::getParameter(std::string const &parameterName) const {
113 return m_presenter->getParameter(parameterName);
114}
115
121void FunctionBrowser::updateParameters(const IFunction &fun) { m_presenter->updateParameters(fun); }
122
126std::string FunctionBrowser::getFunctionString() { return m_presenter->getFunctionString(); }
127
129
130bool FunctionBrowser::hasFunction() const { return m_presenter->hasFunction(); }
131
133int FunctionBrowser::getNumberOfDatasets() const { return m_presenter->getNumberOfDatasets(); }
134
136std::vector<std::string> FunctionBrowser::getDatasetNames() const { return m_presenter->getDatasetNames(); }
137
139std::vector<std::string> FunctionBrowser::getDatasetDomainNames() const { return m_presenter->getDatasetDomainNames(); }
140
143void FunctionBrowser::setNumberOfDatasets(int n) { m_presenter->setNumberOfDatasets(n); }
144
148void FunctionBrowser::setDatasets(const std::vector<std::string> &datasetNames) {
149 m_presenter->setDatasets(datasetNames);
150}
151
155void FunctionBrowser::setDatasets(const QList<FunctionModelDataset> &datasets) { m_presenter->setDatasets(datasets); }
156
162double FunctionBrowser::getLocalParameterValue(std::string const &parameterName, int i) const {
163 return m_presenter->getLocalParameterValue(parameterName, i);
164}
165
166void FunctionBrowser::setLocalParameterValue(std::string const &parameterName, int i, double value) {
167 m_presenter->setLocalParameterValue(parameterName, i, value);
168}
169
170void FunctionBrowser::setLocalParameterValue(std::string const &parameterName, int i, double value, double error) {
171 m_presenter->setLocalParameterValue(parameterName, i, value, error);
172}
173
175double FunctionBrowser::getLocalParameterError(std::string const &parameterName, int i) const {
176 return m_presenter->getLocalParameterValue(parameterName, i);
177}
178
180
182void FunctionBrowser::setCurrentDataset(int i) { m_presenter->setCurrentDataset(i); }
183
186void FunctionBrowser::removeDatasets(const QList<int> &indices) { m_presenter->removeDatasets(indices); }
187
190void FunctionBrowser::addDatasets(const std::vector<std::string> &names) { m_presenter->addDatasets(names); }
191
194
199void FunctionBrowser::setLocalParameterFixed(std::string const &parameterName, int i, bool fixed) {
200 m_presenter->setLocalParameterFixed(parameterName, i, fixed);
201}
202
206bool FunctionBrowser::isLocalParameterFixed(std::string const &parameterName, int i) const {
207 return m_presenter->isLocalParameterFixed(parameterName, i);
208}
209
213std::string FunctionBrowser::getLocalParameterTie(std::string const &parameterName, int i) const {
214 return m_presenter->getLocalParameterTie(parameterName, i);
215}
216
221void FunctionBrowser::setLocalParameterTie(std::string const &parameterName, int i, std::string const &tie) {
222 m_presenter->setLocalParameterTie(parameterName, i, tie);
223}
224
228 m_presenter->updateMultiDatasetParameters(fun);
229}
230
234 m_presenter->updateMultiDatasetAttributes(fun);
235}
236
238 auto const nRows = paramTable.rowCount();
239 if (nRows == 0)
240 return;
241
242 auto const globalParameterNames = getGlobalParameters();
243 for (auto &&name : globalParameterNames) {
244 auto valueColumn = paramTable.getColumn(name);
245 auto errorColumn = paramTable.getColumn(name + "_Err");
246 setParameter(name, valueColumn->toDouble(0));
247 setParameterError(name, errorColumn->toDouble(0));
248 }
249
250 auto const localParameterNames = getLocalParameters();
251 for (auto &&name : localParameterNames) {
252 auto valueColumn = paramTable.getColumn(name);
253 auto errorColumn = paramTable.getColumn(name + "_Err");
254 if (nRows > 1) {
255 for (size_t i = 0; i < nRows; ++i) {
256 setLocalParameterValue(name, static_cast<int>(i), valueColumn->toDouble(i), errorColumn->toDouble(i));
257 }
258 } else {
259 auto const i = getCurrentDataset();
260 setLocalParameterValue(name, i, valueColumn->toDouble(0), errorColumn->toDouble(0));
261 }
262 }
263}
264
266int FunctionBrowser::getCurrentDataset() const { return m_presenter->getCurrentDataset(); }
267
272void FunctionBrowser::setColumnSizes(int s0, int s1, int s2) { m_presenter->setColumnSizes(s0, s1, s2); }
273
278void FunctionBrowser::setStretchLastColumn(bool stretch) { m_presenter->setStretchLastColumn(stretch); }
279
284void FunctionBrowser::setErrorsEnabled(bool enabled) { m_presenter->setErrorsEnabled(enabled); }
285
290
291std::vector<std::string> FunctionBrowser::getGlobalParameters() const { return m_presenter->getGlobalParameters(); }
292
293std::vector<std::string> FunctionBrowser::getLocalParameters() const { return m_presenter->getLocalParameters(); }
294
295void FunctionBrowser::setGlobalParameters(std::vector<std::string> const &globals) {
296 m_presenter->setGlobalParameters(globals);
297}
298
299std::optional<std::string> FunctionBrowser::currentFunctionIndex() { return m_presenter->currentFunctionIndex(); }
300
301FunctionTreeView *FunctionBrowser::view() const { return dynamic_cast<FunctionTreeView *>(m_presenter->view()); }
302
303std::string FunctionBrowser::getFitFunctionString() const { return m_presenter->getFitFunctionString(); }
304
305void FunctionBrowser::setBackgroundA0(double value) { m_presenter->setBackgroundA0(value); }
306
308
310
311} // namespace MantidQt::MantidWidgets
std::string name
Definition Run.cpp:60
double value
The value of the point.
Definition FitMW.cpp:51
double error
std::map< DeltaEMode::Type, std::string > index
std::vector< std::string > getDatasetNames() const override
Get the names of datasets.
void clear() override
Clear the contents.
void removeDatasets(const QList< int > &indices)
Remove local parameter values for a number of datasets.
void setCurrentDataset(int i) override
Set current dataset.
std::vector< std::string > getLocalParameters() const
Get a list of names of local parameters.
IFunction_sptr getFunctionByIndex(std::string const &index)
Return a function with specified index.
void setNumberOfDatasets(int n) override
Set new number of the datasets.
std::vector< std::string > getGlobalParameters() const
Get a list of names of global parameters.
void setStretchLastColumn(bool stretch)
Set the last column to stretch.
void setGlobalParameters(std::vector< std::string > const &globals)
void attributeChanged(std::string const &attributeName)
void updateMultiDatasetAttributes(const IFunction &fun)
Update parameter values in the browser to match those of a function.
std::vector< std::string > getDatasetDomainNames() const override
Get the names of the dataset domains.
std::string getFunctionString() override
Return FunctionFactory function string.
void parameterChanged(std::string const &funcIndex, std::string const &paramName)
void clearErrors() override
Clear all errors.
void addDatasets(const std::vector< std::string > &names)
Add some datasets to those already set.
bool isLocalParameterFixed(std::string const &parameterName, int i) const override
Check if a local parameter is fixed.
virtual ~FunctionBrowser() override
Destructor.
void setParameter(std::string const &parameterName, double value)
Update the function parameter value.
double getLocalParameterError(std::string const &parameterName, int i) const
Get error of a local parameter.
double getParameter(std::string const &parameterName) const
Get a value of a parameter.
void setParameterError(std::string const &parameterName, double error)
Update the function parameter error.
int getNumberOfDatasets() const override
Get the number of datasets.
IFunction_sptr getGlobalFunction() override
Return the multidomain function if number of datasets is greater than 1.
std::unique_ptr< FunctionMultiDomainPresenter > m_presenter
void setColumnSizes(int s0, int s1, int s2=-1)
Resize the browser's columns.
bool hasFunction() const
Check if a function is set.
void setLocalParameterFixed(std::string const &parameterName, int i, bool fixed) override
Fix/unfix local parameter.
void setLocalParameterValue(std::string const &parameterName, int i, double value) override
Set value of a local parameter.
std::string getLocalParameterTie(std::string const &parameterName, int i) const override
Get the tie for a local parameter.
IFunction_sptr getFunction()
Return the function.
void setBackgroundA0(double value)
Set a parameter that is responsible for the background level.
void setErrorsEnabled(bool enabled) override
Set error display on/off.
void setFunction(std::string const &funStr) override
Set the function in the browser.
void updateMultiDatasetParameters(const IFunction &fun) override
Update parameter values in the browser to match those of a function.
std::optional< std::string > currentFunctionIndex()
Return index of the current function, if one is selected.
void setDatasets(const std::vector< std::string > &datasetNames) override
Sets the datasets being fitted.
int getCurrentDataset() const override
Get the index of the current dataset.
FunctionBrowser(QWidget *parent=nullptr, bool multi=false, const std::vector< std::string > &categories=std::vector< std::string >())
Constructor.
void updateParameters(const IFunction &fun) override
Update parameter values in the browser to match those of a function.
void setLocalParameterTie(std::string const &parameterName, int i, std::string const &tie) override
Set a tie for a local parameter.
double getLocalParameterValue(std::string const &parameterName, int i) const override
Get value of a local parameter.
Class FitPropertyBrowser implements QtPropertyBrowser to display and control fitting function paramet...
This is an interface to a fitting function - a semi-abstarct class.
Definition IFunction.h:166
ITableWorkspace is an implementation of Workspace in which the data are organised in columns of same ...
virtual Column_sptr getColumn(const std::string &name)=0
Gets the shared pointer to a column by name.
virtual size_t rowCount() const =0
Number of rows in the workspace.
The Logger class is in charge of the publishing messages from the framework through various channels.
Definition Logger.h:51
std::shared_ptr< IFunction > IFunction_sptr
shared pointer to the function base class
Definition IFunction.h:743
Kernel::Logger g_log("DetermineSpinStateOrder")